Commit Graph

2047 Commits

Author SHA1 Message Date
Dodji Seketeli
817a2755bc Bug 26261 - Fix logic for canonicalizing DW_TAG_subroutine_type DIEs
In the function compare_dies, the handling of DW_TAG_subroutine_type
was unfinished.

This DIE represents function types pointed-to by function pointer.  It
doesn't represent the type of a "real" function type like the
abigail::ir::function_type would.  The represent more an interface to
a function, which a pointer can point to or which can be used to issue
a call.

So intended idea is that compare_dies compares two DIEs of the
DW_TAG_subroutine_type and DW_TAG_subprogram kind (the later
represents real function definitions) among other kinds, structurally,
but by trying to optimize for speed, for the purpose of canonicalizing
DIEs even before type canonicalization happens at the libabigail IR
level.  This is critical to save space (and time) by doing DIE
de-duplication on huge binaries.

This patch finishes to implement the comparison for
DW_TAG_subroutine_type and comes with a carefully crafted test case
that hits that code path.

	* src/abg-dwarf-reader.cc (compare_dies): Get out early if we are
	are in the middle of a potential recursive comparison of function
	types.  Likewise if we detect that the two function types have
	different textual representations, linkage names, or have a the
	same textual representation, linkage names and are defined in the
	same translation unit.
	* tests/data/test-read-dwarf/PR26261/PR26261-exe: New test binary
	input file.
	* tests/data/test-read-dwarf/PR26261/PR26261-exe.abi: New
	reference test output file.
	* tests/data/test-read-dwarf/PR26261/PR26261-main.c: Source code
	of the binary above.
	* tests/data/test-read-dwarf/PR26261/PR26261-obj{a,b}.{c,h}:
	Likewise.
	* tests/data/test-read-dwarf/PR26261/Makefile: Makefile to
	build the exe out of the source files.
	* tests/data/Makefile.am: Add the new test input files to source
	distribution.
	* tests/test-read-dwarf.cc (in_out_spec): Add the binary test
	input above to the test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-08-03 11:41:08 +02:00
Dodji Seketeli
63cfd6142c dwarf-reader: re-indent a block of code
While looking at something else, I noticed that a block of code in
compare_dies wasn't properly indented.  Fixed thus.

	* src/abg-dwarf-reader.cc (compare_dies): Properly indent a
	sub-block of the big switch case statement in there.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-30 17:09:11 +02:00
Giuliano Procida
fd8640dc09 abg-ir.cc: Remove duplicated line of code
The commit

dbef379a Support incomplete enums in core and diff code.

added a duplicated line of code in error. This commit removes it.

	* src/abg-ir.cc (decl_base::set_definition_of_declaration):
	Remove duplicated assignment statement.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-28 18:52:57 +02:00
Giuliano Procida
ca956fb48e abg-writer.cc: Fix indentation of XML output
The XML writer produces valid XML. However, it differs in a few
respects from that obtained with xmllint --format.

- there is no XML declaration at the start
- attributes use single quotes rather than double quotes
- indentation is mostly 2 spaces but this is broken in places

This commit fixes the last of these issues as it actually causes
readability issues when examining diffs. It also does this for every
test XML file, whether used as input, compared against output or not
used at all, to match what xmllint --format would do.

	* src/abg-writer.cc (write_canonical_types_of_scope): Do not
	add additional indentation. (write_translation_unit): Pass
	additional indentation to write_canonical_types_of_scope.
	(write_class_decl): Ensure optional annotations of base
	classes have the same indentation as the base classes
	themselves.
	* tests/data/test-annotate/libtest23.so.abi: Fix indentation.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Ditto.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Ditto.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi:
	Ditto.
	* tests/data/test-annotate/test1.abi: Ditto.
	* tests/data/test-annotate/test14-pr18893.so.abi: Ditto.
	* tests/data/test-annotate/test15-pr18892.so.abi: Ditto.
	* tests/data/test-annotate/test17-pr19027.so.abi: Ditto.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Ditto.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Ditto.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Ditto.
	* tests/data/test-annotate/test21-pr19092.so.abi: Ditto.
	* tests/data/test-diff-suppr/test45-abi-wl.xml: Ditto.
	* tests/data/test-diff-suppr/test45-abi.xml: Ditto.
	* tests/data/test-diff-suppr/test46-PR25128-base.xml: Ditto.
	* tests/data/test-diff-suppr/test46-PR25128-new.xml: Ditto.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Ditto.
	* tests/data/test-read-dwarf/libtest23.so.abi: Ditto.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Ditto.
	* tests/data/test-read-dwarf/test1.abi: Ditto.
	* tests/data/test-read-dwarf/test1.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Ditto.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Ditto.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Ditto.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Ditto.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Ditto.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Ditto.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Ditto.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Ditto.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Ditto.
	* tests/data/test-read-write/test10.xml: Ditto.
	* tests/data/test-read-write/test15.xml: Ditto.
	* tests/data/test-read-write/test21.xml: Ditto.
	* tests/data/test-read-write/test28-without-std-fns-ref.xml:
	Ditto.
	* tests/data/test-read-write/test28-without-std-vars-ref.xml:
	Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-28 17:07:03 +02:00
Giuliano Procida
6579ea4d54 Remove ABI XML test data file blank lines
Following a change which eliminated the output of extra blank lines in
XML output, it now also makes sense to remove such blank lines from
saved generated XML files.

This commit does this.

	* tests/data/test-abidiff/test-PR18166-libtirpc.so.abi: Remove
	blank lines.
	* tests/data/test-diff-dwarf-abixml/PR25409-librte_bus_dpaa.so.20.0.abi:
	Ditto.
	* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi:
	Ditto.
	* tests/data/test-diff-suppr/test45-abi-wl.xml: Ditto.
	* tests/data/test-diff-suppr/test45-abi.xml: Ditto.
	* tests/data/test-diff-suppr/test46-PR25128-base.xml: Ditto.
	* tests/data/test-diff-suppr/test46-PR25128-new.xml: Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-28 16:21:34 +02:00
Giuliano Procida
2f83b47ba4 abg-ir.cc: Fix incorrect pop of compared types.
In one case there is an attempt to "pop" an in-progress type
comparison which hasn't actually happened.

This commit fixes this.

	* src/abg-ir.cc (equals): In the class_or_union overload,
	replace one instance of RETURN(false) with return false.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-28 15:31:52 +02:00
Giuliano Procida
7401923193 Enable Clang's -Werror-overloaded-virtual.
Ths warning is no longer triggered and can be reenabled.

	* configure.ac: Remove the special clause that disabled
	-Werror-overloaded-virtual for Clang builds.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-27 18:26:16 +02:00
Giuliano Procida
23f11d70de Fix inheritance of scope_decl::insert_member_decl
The classes class_decl, class_or_union and scope_decl derive from each
other. The method insert_member_decl is declared virtual and defined
in each of these. Unfortunately, it has different argument types in
the base scope_decl class.

Most calls to insert_member_decl are at a statically known class, but
in insert_decl_into_scope the method is called via a scope_decl
pointer. There is the possibility that this could be a type derived
from scope_decl rather than scope_decl itself, in which case the base
method would be called, not as intended.

This commit adjusts the type of the member argument to
scope_decl::insert_member_decl to match the other two classes and
eliminates the last trigger of Clang's -Werror-overloaded-virtual.

	* include/abg-ir.h (scope_decl::insert_member_decl): Change
	type of member argument from const decl_base_sptr& to plain
	decl_base_sptr.
	* src/abg-ir.cc (scope_decl::insert_member_decl): Likewise.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-27 18:04:05 +02:00
Dodji Seketeli
38b1476765 Pimpl-ify traversable_base and remove its unused traverse method
The traverse method is defined in the traversable_base class but is
never used as the synonymous methods in the derived classes have
different argument types and so hide it.

It's never used because it's mostly intended as documentation for what
the implementations of this interface should look like.  Namely they
should define a traversable method and its parameter type should
derive from the parameter type of traversable_base::traverse.

But apparently, clang's -Werror-overloaded-virtual is not happy about
this.  It flags it as an error.  It's not.  But hey, let's work-around
it then.

So this patch just comments that method out and document its intent.

To make the change somewhat useful, this patch pimpl-ifies this
abg-traverse.h header file to get us one step closer to some a{b,p}i
stability.  The definitions are moved into abg-traverse.cc.

	* include/abg-traverse.h (traversable_base::priv): Declare new type.
	(traverse_base::priv_sptr): Add pointer to private data
	member.
	(traverse_base::visiting_): Move this data member definition into
	traverse_base::priv.
	(traverse_base::{visiting, traverse_base, ~traverse_base}): Move
	definitions out-of-oline.
	(traverse_base::traverse): Comment out.
	* src/abg-traverse.cc (struct traversable_base::priv): Define new
	type.
	(traversable_base::{traversable_base, ~traversable_base, traverse,
	visiting}): Move these previous inline definitions here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-27 17:50:50 +02:00
Giuliano Procida
93fae877d8 Simplify peel_typedef_pointer_or_reference_type
The second argument to this function controls whether CV qualifiers
should be stripped as well as the elements mentioned in the function
name. While it defaults to true, it is now always passed in as false.

The function contains incomplete code for peeling array types. This is
not needed or indeed wanted by its current callers.

This commits removes the peel_qual_type argument and removes the
associated behaviour. It removes the array peeling code.

There are no functional changes apart from no longer performing early
canonicalisation of certain array types.

I looked at the history of this function to see where the behaviours
originated.

bd161caa Make type_has_non_canonicalized_subtype() tighter

The function is added to help make more types, self-referential ones,
candidates for early canonicalisation.

5822798d Bug 18894 - Fix representation of enumerators in abixml format

This undid the previous change but the function remained.

c20c8c79 Fix infinite loop in peel_typedef_pointer_or_reference_type

As it says, fixing the overload that is currently in use.

6e36a438 Late canonicalize all types that reference classes when reading DWARF

This reintroduced the use of the function to control canonicalisation
by the detection of class types. It also added array peeling to the
function, but in a broken fashion as it would only work for certain
combinations of pointers, references or typedefs referring to arrays.

e9bdb488 Bug 19025 - abixml writer forgets to emit some member types

This added a use of the function in a map key comparison function.

8cc382c8 Fix emitting of referenced type in abixml writer

This undid the previous change.

1bee40c0 Do not forget to peel qualified type off when peeling types

This made the function remove CV qualifiers unconditionally.

e73901a5 Do not mark "distinct" diff nodes as being redundant

This made behaviour to remove CV qualifiers optional and newly added
is_mostly_distinct_diff disabled it.

5d6af8d5 Delay canonicalization for array and qualified types

This change switches maybe_canonicalize_type to not request CV
qualifer peeling from peel_typedef_pointer_or_reference_type.

It partially resolves the array type issue as they are separately
checked for. Presumably they shouldn't be peeled, but still are under
some circumstances.

The tests here could be subject to further refinement. Many types have
delayed canonicalisation already.

9cf76b11 abg-ir.cc: Improve types_have_similar_structure.

This change replaced the use of the function with a more delicate
matched peeling process for pointer and reference types plus
peel_qualified_or_typedef_type. It obsoleted the behaviour where CV
qualifiers were stripped.

	* include/abg-fwd.h (peel_qualified_or_typedef_type): Remove
	second argument in declarations of both overloads.
	* src/abg-comp-filter.cc (is_mostly_distinct_diff): Remove
	second argument to peel_qualified_or_typedef_type.
	* src/abg-dwarf-reader.cc (maybe_canonicalize_type): Likewise.
	* src/abg-ir.cc (peel_qualified_or_typedef_type): In both
	overloads, remove second argument peel_qual_type, simplify
	code with the assumption it was always false and remove
	incomplete array type peeling logic. In type_base_sptr
	overload, remove stray space.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-27 15:26:27 +02:00
Giuliano Procida
3b93574beb Remove unused is_reference_or_pointer_diff.
The function is_reference_or_pointer_diff was added in commit

85929105 Fix redundancy marking for change of types used directly

and was updated to peel typedefs as a first step in

ef9d20c9 Fix redundancy detection through fn ptr and typedef paths

which, however, also made it obsolete.

This commit removes the function's declaration and definition.
There are no functional changes.

	* include/abg-comparison.h (is_reference_or_pointer_diff):
	Drop function declaration.
	* src/abg-comparison.cc (is_reference_or_pointer_diff): Drop
	function definition.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-27 15:26:04 +02:00
Giuliano Procida
12baf89751 abg-comparison.h: Remove stray declaration
The functon is_reference_or_pointer_diff_to_non_basic_distinct_types
was declared in

ef9d20c9 Fix redundancy detection through fn ptr and typedef paths

but never defined. This commit removes it. There are no functional
changes.

	* include/abg-comparison
	(is_reference_or_pointer_diff_to_non_basic_distinct_types):
	Remove stray declaration.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-27 15:26:04 +02:00
Giuliano Procida
0fd2fb93eb abg-ir.cc: Refactor operator== methods with helper function
Many of the operator== definitions in this source file follow the same
pattern:

- First, canonical comparison is attempted if canonical types are
  present.
- Otherwise, the comparison is performed structurally using the
  'equals' function.

This commit refactors the common logic into a templated helper
function named "try_canonical_compare".

There are no behavioural changes.

	* src/abg-ir.cc (try_canonical_compare): New template function.
	(type_decl::operator==): Use it here.
	(scope_type_decl::operator==): Likewise.
	(qualified_type_def::operator==): Likewise.
	(pointer_type_def::operator==): Likewise.
	(reference_type_def::operator==): Likewise.
	(array_type_def::subrange_type::operator==): Likewise.
	(array_type_def::operator==): Likewise.
	(enum_type_decl::operator==): Likewise.
	(typedef_decl::operator==): Likewise.
	(function_type::operator==): Likewise.
	(class_or_union::operator==): Likewise.
	(class_decl::operator==): Likewise.
	(union_decl::operator==): Likewise.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-27 15:26:03 +02:00
Giuliano Procida
dfd8314159 abg-comparison.cc: Tidy some corpus_diff code
This commit fixes up some code whitespace for style and consitency,
renames a poorly-named variable and fixes a comment typo.

There are no behavioural changes.

	* src/abg-comparison.cc (corpus_diff::priv::emit_diff_stats):
	Adjust code whitespace; rename the second instance of
	total_nb_variable_changes to
	total_nb_unreachable_type_changes.
	(corpus_diff::has_incompatible_changes): Fix comment typo.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-27 11:59:07 +02:00
Giuliano Procida
be0effa6fd Fix --type-id-style hash for empty internal names.
libabigail's intern_string class treats the empty string specially. It
is not safe to call the raw method without checking for a empty
pointer. It is safe to convert to std::string.

This commit changes the XML writer to convert interned strings to
std::strings before computing their hashes.

	* src/abg-writer.cc (write_context::get_id_for_type): When
	hashing internal type names, convert to std::string rather
	than using the raw method directly as this will avoid a null
	pointer dereference in the case of an empty string; tabify
	code indentation.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-27 11:23:26 +02:00
Giuliano Procida
96ce0785fd abg-ir.cc: Tidy some operator== definitions
Many of the operator== definitions in this source file follow the same
pattern:

- the address of the argument is dynamic_cast to type of 'this'
- naked canonical type pointers are compared, if both present
- the types are compared structurally with 'equals'

In a couple of cases extra work is done to fetch the canonical type
of the definition of a declaration.

This commit adjusts a few cases so they more closely follow the common
form. This is to make the next refactoring trivial.

There are no behavioural changes.

	* src/abg-irc.cc (scope_type_decl::operator==): Compare naked
	canonical type pointers instead of the shared pointers.
	(qualified_type_def::operator==): Remove excess blank line.
	(function_type::operator==): Do dynamic_cast and check of
	argument before comparing naked canonical type pointers.
	(class_or_union::operator==): Eliminate temporary reference.
	(class_decl::operator==): Likewise.
	(union_decl::operator==): Likewise.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-27 09:33:44 +02:00
Giuliano Procida
697347e402 Fix corpus_diff::has_net_changes for --leaf-changes-only mode
This function was not aware of --leaf-changes-only mode.

    - Stats counters for changed variables and types have
      different names in the different modes.
    - Net leaf type changes were not included in leaf mode.

For some inputs, this resulted in abidiff producing an empty report
but returning a non-zero exit status in --leaf-changes-only mode.

For other inputs the combination of both issues still resulted in the
correct return code. This included the following test-abidiff-exit
test cases:

    - test-leaf-peeling
    - test-leaf2
    - test-no-stray-comma

This patch makes corpus_diff::has_net_changes mirror emit_diff_stats,
modulo flags like --non-reachable-types which if absent can still
result in discrepancies between output and return code.

To achieve this in a more maintainable way, the patch introduces a new interface
reporter_base::diff_has_net_changes.  That interface is implemented by
all current reporters.  Each reporter focuses on its own
particularities to provide the required behavious. Then
corpus_diff:has_net_changes just has to invoke
reporter_base::diff_has_net_changes on the reporter that is currently
in used.

The tests below verify that the exit code is zero when all the changes
between the test files are suppressed.

	* include/abg-reporter.h ({reporter_base, default_reporter,
	leaf_reporter}::diff_has_net_changes): Add new virtual function.
	This breaks binary compatibility but should conserve source
	compatibility.
	* src/abg-default-reporter.cc
	(default_reporter::diff_has_net_changes): Define new member
	function.
	* src/abg-leaf-reporter.cc (leaf_reporter::diff_has_net_changes):
	Likewise.
	* src/abg-comparison.cc (corpus_diff::has_net_changes): Invoke
	reporter_base::diff_has_net_changes on the current reporter,
	rather than trying to handle all the different kinds of reporters
	here.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats): Add a
	TODO to possibly delegate the implementation of this function to
	the reporters.
	* tests/data/Makefile.am: Add new test case files.
	* tests/data/test-abidiff-exit/test-net-change-report0.txt:
	Normal mode, nothing suppressed.
	* tests/data/test-abidiff-exit/test-net-change-report1.txt:
	Normal mode, everything suppressed.
	* tests/data/test-abidiff-exit/test-net-change-report2.txt:
	Leaf mode, nothing suppressed.
	* tests/data/test-abidiff-exit/test-net-change-report3.txt:
	Leaf mode, everything suppressions.
	* tests/data/test-abidiff-exit/test-net-change-v0.c: Test file
	* tests/data/test-abidiff-exit/test-net-change-v0.o: Test file
	* tests/data/test-abidiff-exit/test-net-change-v1.c: Test file
	* tests/data/test-abidiff-exit/test-net-change-v1.o: Test file
	* tests/data/test-abidiff-exit/test-net-change.abignore: This
	suppresses changes for all variables, functions and types in
	the test files, except for the 'victim' function.
	* tests/test-abidiff-exit.cc: Run new test cases.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-21 08:53:19 +02:00
Giuliano Procida
e0d29a919d reporter: Fix report whitespace typos.
The patch fixes two minor formatting typos.

	* src/abg-reporter-priv.cc (represent): Add missing space to
	string split across two lines in certain anonymous data member
	diffs.
	* src/abg-default-reporter.cc (report): In the array_diff
	overload, eliminate trailing space at end of line.
	* tests/data/test-diff-dwarf/test10-report.txt: Delete
	trailing whitespace.
	* tests/data/test-diff-filter/test24-compatible-vars-report-1.txt:
	Ditto.
	* tests/data/test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm--libICE-1.0.9-2.el7.x86_64.rpm-report-0.txt:
	Ditto.
	* tests/data/test-diff-pkg/libcdio-0.94-1.fc26.x86_64--libcdio-0.94-2.fc26.x86_64-report.1.txt:
	Ditto.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Ditto.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-10 15:09:33 +02:00
Giuliano Procida
f0bf868022 abg-writer.cc: Clean up new line emission.
The XML writer has a few different styles of new line handling in
different places. Some functions are responsible for line termination,
others are not and there is bespoke logic and state variables in a few
places.

Extra or missing newlines should have no impact on the semantics of
any given ABI file but they do affect textual diffs and diff
statistics.

By insisting the XML emitted should have exactly one XML tag (or
comment) per line, we can simplify the code and make it more
composable.

This commit does this, yielding a modest reduction in code size and
eliminating all blank lines in XML output (7127 blank lines in current
tests). The commit also fixes some code whitespace.

	* src/abg-writer.cc (annotate): In the
	function_decl::parameter_sptr overload, fix code whitespace.
	(write_decl_in_scope): Remove wrote_context state variable and
	associated logic; emit new line unconditionally after end of
	XML tags and nowhere else.
	(write_canonical_types_of_scope): Emit new line after end of
	XML comment and nowhere else.
	(write_translation_unit): Emit new line after end of XML tags
	and nowhere else.
	(write_type_decl): Likewise.
	(write_namespace_decl): Likewise.
	(write_qualified_type_def): Emit new line after end of XML tag.
	(write_pointer_type_def): Likewise.
	(write_reference_type_def): Likewise.
	(write_array_type_def): Emit new line after end of XML tags
	and nowhere else.
	(write_enum_type_decl): Emit new line after end of XML tag.
	(write_elf_symbol): Likewise.
	(write_elf_symbols_table): Emit no new lines.
	(write_elf_needed): Emit new line unconditionally after end of
	XML tags.
	(write_typedef_decl): Emit new line after end of XML tag.
	(write_var_decl): Emit new line after end of XML tag.
	(write_function_decl): Likewise.
	(write_function_type): Fold two output statements into
	one; emit new line after end of XML tag.
	(write_class_decl_opening_tag): Emit new line unconditionally
	after end of XML tags and simplify empty element tag logic.
	(write_union_decl_opening_tag): Likewise.
	(write_class_decl): Emit new line after end of XML tag and
	nowhere else.
	(write_union_decl): Likewise.
	(write_member_type_opening_tag): Emit new line after end of
	XML tag.
	(write_member_type): Emit new lines only after XML tags.
	(write_type_tparameter): Emit new line after XML tag.
	(write_non_type_tparameter): Likewise.
	(write_template_tparameter): Emit new line after XML tag and
	nowhere else.
	(write_type_composition): Likewise.
	(write_template_parameters): Emit no new lines.
	(write_function_tdecl): Emit new line after XML tag and
	nowhere else.
	(write_class_tdecl): Likewise.
	(write_corpus): Emit new lines only after XML tags.
	(dump): In the decl_base_sptr overload, don't emit final new
	line as this is now done by write_decl. In the var_decl_sptr
	overload, don't emit final new line (mistakenly done to cerr
	instead of o) as this is now done by write_var_decl. In the
	translation_unit overload, don't emit final new line as this
	doubles that emitted by write_translation_unit.
	* tests/data/test-annotate/libtest23.so.abi: Delete all blank
	lines.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Ditto.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Ditto.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi:
	Ditto.
	* tests/data/test-annotate/test1.abi: Ditto.
	* tests/data/test-annotate/test13-pr18894.so.abi: Ditto.
	* tests/data/test-annotate/test14-pr18893.so.abi: Ditto.
	* tests/data/test-annotate/test15-pr18892.so.abi: Ditto.
	* tests/data/test-annotate/test17-pr19027.so.abi: Ditto.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Ditto.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Ditto.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Ditto.
	* tests/data/test-annotate/test21-pr19092.so.abi: Ditto.
	* tests/data/test-annotate/test7.so.abi: Ditto.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Ditto.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Ditto.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Ditto.
	* tests/data/test-read-dwarf/libtest23.so.abi: Ditto.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Ditto.
	* tests/data/test-read-dwarf/test1.abi: Ditto.
	* tests/data/test-read-dwarf/test1.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Ditto.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Ditto.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Ditto.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Ditto.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Ditto.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Ditto.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Ditto.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Ditto.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Ditto.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test7.so.abi: Ditto.
	* tests/data/test-read-dwarf/test7.so.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi:
	Ditto.
	* tests/data/test-read-write/test10.xml: Ditto.
	* tests/data/test-read-write/test15.xml: Ditto.
	* tests/data/test-read-write/test21.xml: Ditto.
	* tests/data/test-read-write/test25.xml: Ditto.
	* tests/data/test-read-write/test28-without-std-fns-ref.xml:
	Ditto.
	* tests/data/test-read-write/test28-without-std-vars-ref.xml:
	Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-09 19:10:12 +02:00
Dodji Seketeli
3506ba5795 reader: Remove useless support for WIP types
In the abixml reader, WIP types are tracked to know if a type has been
fully constructed yet or not.  This information is later useful to
know if a given type should be canonicalized right away, or if its
canonicalization should be delayed until the entire abixml file has
been read.

Right now, with all the evolutions that happened in the abixml reader,
only scalar types are canonicalized right away.  All other types are
canonicalized late, meaning, after the entire abixml file is read.
This doesn't have any noticeable performance impact because the volume
of types coming from an abixml file is relatively small enough,
compared to what we can see in a DWARF/ELF binary due to type
duplication.

So the whole WIP tracking becomes is now pretty much useless, in
practise.  So this patch does away with it altogether.

	* src/abg-reader.cc (read_context::m_wip_types_map): Remove data
	member.
	(read_context::{clear_wip_classes_map, mark_type_as_wip,
	unmark_type_as_wip, is_wip_type}): Remove member functions.
	(read_context::maybe_canonicalize_type): Remove use of
	is_wip_type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-09 14:44:57 +02:00
Giuliano Procida
8e8e0778f2 Use pointers not strings in type graph comparison.
During structural comparison of types there is the possibilitiy of
infinite recursion as types can have self-references and there can
be more elaborate mutual references between them.

The current comparison algorithm keeps track of currently seen (struct
and function) types by name. This causes earlier caching of names than
is needed and, more significantly, may result in types comparing equal
unexpectedly. This commit switches to storing their addresses instead.

This change affects some tests which show more diffs than previously.

	src/abg-ir.cc: (environment::priv): Change types of
	classes_being_compared_ and fn_types_being_compared_ to be
	simple sets of pointers.
	(function_type::priv::mark_as_being_compared): Just add
	address to set.
	(function_type::priv::unmark_as_being_compared): Just remove
	address from set.
	(function_type::priv::comparison_started): Just look up
	address in set.
	(class_or_union::priv::mark_as_being_compared): Just add
	address to set.
	(class_or_union::priv::unmark_as_being_compared): Just remove
	address from set.
	(class_or_union::priv::comparison_started): Just look up
	address in set.
	* tests/data/test-diff-dwarf/PR25058-liblttng-ctl-report-1.txt:
	Update.
	* tests/data/test-diff-pkg/elfutils-libs-0.170-4.el7.x86_64-multiple-sym-vers-report-0.txt:
	Update.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Update.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt:
	Update.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-09 10:02:53 +02:00
Giuliano Procida
b0f98180e0 Add tests for declaration-only enums.
* tests/data/test-abidiff-exit/test-decl-enum-report-2.txt: Add
	new test reference output.
	* tests/data/test-abidiff-exit/test-decl-enum-report-3.txt: Likewise.
	* tests/data/test-abidiff-exit/test-decl-enum-report.txt: Likewise.
	* tests/data/test-abidiff-exit/test-decl-enum-v{0,1}.c: Add source
	code for the binaries below.
	* tests/data/test-abidiff-exit/test-decl-enum-v{0,1}.o: Add new
	binary test inputs.
	* tests/data/Makefile.am: Add the new files above to source
	distribution.
	* tests/test-abidiff-exit.cc: Add the test inputs above to the
	test harness.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-08 16:59:56 +02:00
Giuliano Procida
6295ff70ef Add declaration-only enums to XML reader/writer.
* src/abg-reader.cc (build_enum_type_decl): Detect a
	declaration-only enum and flag it as such.
	(build_type_decl): Support reading the "is-declaration" attribute.
	(build_class_decl): Adjust.
	* src/abg-writer.cc (write_is_declaration_only): Renamed
	write_class_or_union_is_declaration_only into this.
	(write_enum_is_declaration_only): Remove.
	(write_type_decl, write_enum_type_decl)
	(write_class_decl_opening_tag, write_union_decl_opening_tag): Use
	write_is_declaration_only.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-08 16:59:56 +02:00
Dodji Seketeli
9a113ce771 Support declaration-only enums in DWARF reader.
This patch adds declaration-only handling enums to the DWARF reader.

	* src/abg-dwarf-reader.cc (string_enums_map): Define new
	convenience typedef.
	(read_context::decl_only_enums_map_): Define new data member.
	(read_context::{declaration_only_enums,
	is_decl_only_enum_scheduled_for_resolution,
	resolve_declaration_only_enums}): Define new member functions.
	(build_internal_underlying_enum_type_name)
	(build_enum_underlying_type): Factorize these functions out of ...
	(build_enum_type): ... here.  Detect a decl-only enum and flag it
	as such.  If the enum type is decl-only, then set its underlying
	type as decl-only as well.
	(build_enum_underlying_type): Mark the underlying type as
	artificial.
	(get_opaque_version_of_type): Make this handle enums as well.  So
	make its return type be type_or_decl_base_sptr, rather than just
	class_or_union_sptr as it used to be.
	(read_debug_info_into_corpus): Add logging to trace decl-only
	enums resolution.
	(build_ir_node_from_die): Detect when a suppression specification
	makes an enum opaque.  In that case, get an opaque version of the
	enum type by invoking get_opaque_version_of_type.  Note that
	get_opaque_version_of_type doesn't support returning opaque
	-- i.e, decl-only enum types -- yet, but this is going to be
	handled in a subsequent patch.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-08 16:59:56 +02:00
Giuliano Procida
dbef379a96 Support incomplete enums in core and diff code.
This is an initial implementation of the support for incomplete, also
known as forward-declared, enum types. I've not made any attempt to
refactor or share logic with the struct/union code.

	* include/abg-comp-filter.h (has_decl_only_def_change) : Declare
	New function.
	* src/abg-comp-filter.cc (there_is_a_decl_only_enum): Define new
	static function and ...
	(type_size_changed): ... use it here.
	(has_decl_only_def_change): Define new function and ...
	(categorize_harm{less, ful}_diff_node): ... use it here.
	* include/abg-fwd.h (enums_type, decl_base_wptr): Declare new
	typedefs.
	(look_through_decl_only_class): Declare new overload for
	class_or_union*.
	(is_compatible_with_enum_type, is_compatible_with_enum_type)
	(look_through_decl_only, lookup_enum_types, lookup_enum_types):
	Declare new functions.
	* include/abg-ir.h (decl_base::{get_is_declaration_only,
	set_is_declaration_only, set_definition_of_declaration,
	get_definition_of_declaration,
	get_naked_definition_of_declaration}): Declare new member
	functions.  They were moved here from the class_or_union class.
	(class_or_union::{get_earlier_declaration,
	set_earlier_declaration, get_definition_of_declaration,
	set_definition_of_declaration,
	get_naked_definition_of_declaration, get_is_declaration_only,
	set_is_declaration_only}): Remove these member functions.
	* src/abg-ir.cc (decl_base::priv::{declaration_,
	definition_of_declaration_, naked_definition_of_declaration_,
	is_declaration_only_}): Define data members.  Moved here from
	class_or_union.
	(decl_base::priv::priv): Adjust to initialize the new data
	members.
	(decl_base::{get_earlier_declaration, set_earlier_declaration,
	get_definition_of_declaration,
	get_naked_definition_of_declaration, get_is_declaration_only,
	set_is_declaration_only, set_definition_of_declaration}): Define
	member functions.
	(operator|): In the overload for (change_kind, change_kind),
	adjust the return type of the call to
	decl_base::get_definition_of_declaration.
	(look_through_decl_only): Define new function.
	(look_through_decl_only_class): Adjust.
	(look_through_decl_only_enum): Likewise.
	(maybe_update_types_lookup_map<class_decl>): Adjust return type of
	call to decl_base::get_definition_of_declaration.
	(types_defined_same_linux_kernel_corpus_public): Use
	look_through_decl_only_class rather than open coding it.
	(class_or_union::priv::{declaration_, definition_of_declaration_,
	naked_definition_of_declaration_, is_declaration_only_}): Remove
	these data members.  They are now carried by decl_base::priv.
	(class_or_union::{g,s}et_alignment_in_bits): Adjust.
	(class_or_union::{g,s}et_size_in_bits): Likewise.
	(class_or_union::operator==): Likewise.
	(equals): Adjust the overload for class_or_union.
	(is_compatible_with_enum_type)
	* src/abg-comparison.cc (try_to_diff<class_decl>): Adjust the
	return type of decl_base::get_definition_of_declaration.
	(leaf_diff_node_marker_visitor::visit_begin): Use
	filtering::has_decl_only_def_change rather than
	filtering::has_class_decl_only_def_change.  Decl-only changes to
	enums (or any other type really) will thus not be recorded as leaf
	changes.
	* src/abg-dwarf-reader.cc (get_scope_for_die): Adjust return type
	of decl_base::get_definition_of_declaration.
	* src/abg-default-reporter.cc (default_reporter::report): Report
	enum decl-only <-> definition changes.
	* src/abg-hash.cc (class_or_union:#️⃣:operator()): In the
	overload for class_or_union& adjust the return type for
	decl_base::get_definition_of_declaration.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-08 16:59:56 +02:00
Giuliano Procida
401e3cded9 abg-ir.cc: Remove unused re_canonicalize function.
The function re_canonicalize was added in commit:

  286cadf8 Bug 24430 - Fold away const for array types

but later rendered obsolete by commit:

  5d6af8d5 Delay canonicalization for array and qualified types

This commit removes the function and its associated declarations.

	* include/abg-fwd.h (re_canonicalize): Remove declaration of
	obsolete function.
	* include/abg-ir.h (class {decl_base, type_base}): Remove
	re_canonicalize friend declarations from these classes.
	* src/abg-ir.cc (re_canonicalize): Remove obsolete function.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-07-07 16:26:47 +02:00
Dodji Seketeli
346e88dd76 Bug 26135 - Wrong linkage name causes anonymous classes miscomparison
When comparing decls, the overload of the 'equals' function for
instances of decl_base compares their linkage names.  If they are
different, then the decls are generally considered different.

Class declarations (and definitions) also use the 'equals' function
referred to above.  So when two classes have different linkage names,
they are always considered different.

Now let's consider the case of an anonymous class.  It doesn't have
any user-provided name, by definition.  Libabigail does, however,
assigns it an internal name for various (internal) purposes.  That
internal name is generally ignored for the purpose of (anonymous) type
comparison.  So by design, two anonymous classes can have different
internal anonymous names and yet still happen to be equal.

The root issue in this problem report is that by default, the linkage
name of a class is set to its name.  And when that class is anonymous,
its internal name is used as its linkage name.  Oops.  That leads to
anonymous classes being wrongly considered different.

This patch fixes the issue by providing additional constructors for a
class type to avoid using the internal anonymous name as its linkage
name.

Note that the same issue is present for unions so the patch does the
a similar thing for union types.

Enums are properly handled so we don't need to do anything in that
regard.

For good measure, the patch also adds an assert to
type_base::get_canonical_types_for to ensure that anonymous class or
union types don't have linkage names for now.

	* include/abg-ir.h (class_decl::class_decl): Add two overloads
	that take the "is_anonymous" flag.
	(union_decl::union_decl): Likewise.
	* src/abg-ir.cc (class_decl::class_decl): Define two overloads
	that take the "is_anonymous" flag and set the linkage name
	accordingly.
	(union_decl::union_decl): Likewise.
	(type_base::get_canonical_type_for): Assert that an anonymous
	class or union can't have a linkage name for now.
	* src/abg-dwarf-reader.cc (add_or_update_class_type)
	(add_or_update_union_type): Use a new overload for the constuctor
	of {class, union}_decl and set the "is_anonymous" flag.  Don't use
	decl_base::set_is_anonymous anymore.
	* src/abg-reader.cc (build_class_decl, build_union_decl):
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-07-06 18:26:08 +02:00
Giuliano Procida
dd1c608120 Rename declaration-definition change category.
This patch renames CLASS_DECL_ONLY_DEF_CHANGE_CATEGORY to
TYPE_DECL_ONLY_DEF_CHANGE_CATEGORY.

	* include/abg-comparison.h (TYPE_DECL_ONLY_DEF_CHANGE_CATEGORY):
	Rename CLASS_DECL_ONLY_DEF_CHANGE_CATEGORY into this.
	(EVERYTHING_CATEGORY): In the value of this enumerator, rename
	CLASS_DECL_ONLY_DEF_CHANGE_CATEGORY into
	TYPE_DECL_ONLY_DEF_CHANGE_CATEGORY.
	* src/abg-comp-filter.cc (categorize_harmless_diff_node):
	Likewise.
	* src/abg-comparison.cc (get_default_harmless_categories_bitmap):
	Likewise.
	(operator<<(ostream& o, diff_category c)): Likewise.
	* src/abg-default-reporter.cc (default_reporter::report): Likewise
	in the overload for class_or_union_diff.
	* src/abg-leaf-reporter.cc (leaf_reporter::report): Likewise in
	the overload for class_or_union_diff.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-06-29 18:06:21 +02:00
Giuliano Procida
2b2f073d7a Tidy build_enum_type state variables.
This patch brings the enum code closer to the class/union code, in the
hope that this will ease future code maintenance.

There are no behavioural changes.

	* src/abg-dwarf-reader.cc (build_enum_type): Rename local
	variable enum_is_anonymous to is_anonymous. Move initilisation
	of local variable is_artificial to location corresponding to
	that in add_or_update_class_type and add_or_update_union_type
	functions.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-06-29 11:06:14 +02:00
Giuliano Procida
56db287aba Refactor d.context() as ctxt in report(enum_diff).
* src/abg-default-reporter.cc (report): In the enum_diff
	overload, introduce the name ctxt to replace four occurrences
	of d.context().

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-06-29 10:30:21 +02:00
Giuliano Procida
df47240f7d Improve code comments and whitespace.
These are zero impact changes.

	* include/abg-fwd.h: Correct doc-comment reference to
	enum_type_decl.
	* src/abg-comp-filter.cc: Fix doc-comment syntax.
	* src/abg-comparison.cc (operator<<): In the diff_category
	overload, fix code indentation.
	* src/abg-default-reporter.cc (report): In the
	class_or_union_diff overload, adjust comment to reflect that
	the code is reporting changes between declaration-only and
	defined types, in either direction.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-06-25 17:49:57 +02:00
Giuliano Procida
5f1945b130 get_canonical_type_for: restore environment better
The method type_base::get_canonical_type_for contains some logic which
temporarily changes a couple of control flags in the type's
environment. It then restores these, but not consistently.

This patch ensures the flags are restored unconditionally.

	* src/abg-ir.cc (get_canonical_type_for): Ensure the
	do_on_the_fly_canonicalization and
	decl_only_class_equals_definition flags are restored
	unconditionally.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-06-24 07:31:17 +02:00
Dodji Seketeli
a5d02b95a6 Bug 26127 - abidw --annotate emits incomplete function types
When we get the qualified name of a pointer type, the result is cached
so that subsequent invocations of the getter yields a faster result.

When the pointed-to type is not yet fully constructed at the time of
the first invocation of the getter of the qualified name, what is
cached is the name of the pointer to a non-yet fully qualified type.

Then after the pointed-to type is fully constructed (and
canonicalized), the pointer type also becomes canonicalized (in that
order) and thus, the cache needs to be invalidated so that the
qualified name of the pointer to the fully qualified type is cached
again by a subsequent invocation of the getter.

The problem in this problem report is that the cache doesn't get
invalidated when the pointer type is canonicalized.

This patch fixes that.  A similar issue exists with reference and
qualified types so the patch addresses it for those types as well.

	* include/abg-ir.h (decl_base::clear_qualified_name): Declare new
	protected member function.
	({pointer_type_def, reference_type_def, qualified_type_def,
	function_type}::on_canonical_type_set): Declare virtual member
	functions.
	* src/abg-ir.cc (decl_base::clear_qualified_name): Define new
	protected member function.
	({pointer_type_def, reference_type_def, qualified_type_def,
	function_type}::on_canonical_type_set): Define virtual member
	functions.
	* tests/data/test-annotate/test17-pr19027.so.abi: Adjust.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-06-18 15:07:34 +02:00
Giuliano Procida
84fc161a0b Fix bug that suppressed DWARF read tests.
Commit 4252dfd6 added code to allow the ABI write/reread and compare
phases of the tests to be skipped in the case that no ABI files are
given for comparison.

Unfortunately, the new code skipped those phases unconditionally.

This patch changes the in_abi_path and out_abi_path values used in
in_out_specs used to trigger the early termination from "" to NULL and
updates the conditional logic checking them. Several subsequent
commits which affect ABI output were missing these changes to the test
data files.

This change fixes the following list of commits.

4252dfd6 dwarf-reader: handle symtab.section_header.sh_entsize == 0
4457c10e dwarf-reader: handle binaries with missing symtab
34e867e7 dwarf-reader: remove superfluous ABG_ASSERT
2d5389f2 Fix size calculations for multidimensional arrays.
246ca200 corpus/writer: sort emitted translation units by path name
e8bf5b80 Bug 25989 - type_topo_comp doesn't meet irreflexive requirements

Finally, this commit also corrects some bad code formatting.

	* tests/test-read-dwarf.cc (in_out_specs): Use NULL instead of
	empty ABI paths for test25, test26 and test27. (perform):
	Check members of spec, rather than locals with same name, when
	deciding to terminate testing early; fix some code whitespace.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Update
	multidimensional array sizes.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Ditto.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test7.so.abi: Ditto.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Update following translation unit ordering change.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Ditto.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Ditto.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Ditto.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Ditto.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Ditto.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Ditto.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Ditto.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Update
	following code changes affecting ordering of some ABI
	elements.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi

Reviewed-by: Matthias Maennich <maennich@google.com>
Tested-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-06-17 11:27:13 +02:00
Matthias Maennich
b7e9acc4cc cleanup: std::weak_ptr use: replace manual lock by std::weak_ptr::lock
The pattern

	expired() ? shared_ptr<T>() : shared_ptr<T>(*this)

on std::weak_ptr<T> can be simplified by using std::weak_ptr<T>::lock.
Since weak_ptr::lock does this atomically, this patch also addresses
potential data races between the call to expired() and the construction
based on the assumption that the shared_ptr is still around.
Hence, apply this simplification/fix to the code base.

	* src/abg-comparison-priv.h (diff::priv::get_context): improve
	weak_ptr usage.
	(corpus_diff:diff_stats::priv::ctxt): Likewise.
	* src/abg-comparison.cc (corpus_diff::priv::get_context): Likewise.
	(var_diff::type_diff): Likewise.
	* src/abg-ir.cc (elf_symbol::get_next_alias): Likewise.
	(elf_symbol::get_next_common_instance): Likewise.
	(type_base::get_canonical_type): Likewise.
	(qualified_type_def::get_underlying_type): Likewise.
	(pointer_type_def::get_pointed_to_type): Likewise.
	(reference_type_def::get_pointed_to_type): Likewise.
	(array_type_def::subrange_type::get_underlying_type): Likewise.
	(array_type_def::get_element_type): Likewise.
	(typedef_decl::get_underlying_type): Likewise.
	(var_decl::get_type): Likewise.
	(function_type::get_return_type): Likewise.
	(function_decl::get_type): Likewise.
	(function_decl::parameter::get_type): Likewise.
	(class_or_union::get_naming_typedef): Likewise.
	(class_or_union::get_definition_of_declaration): Likewise.
	(class_decl::base_spec::get_base_class): Likewise.
	(template_parameter::get_enclosing_template_decl): Likewise.
	(non_type_tparameter::get_type): Likewise.
	(type_composition::get_composed_type): Likewise.

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-06-17 09:54:01 +02:00
Giuliano Procida
4e256018d3 Fix leaf-mode formatting of decl <-> defn diffs.
This commit adds a missing newline.

	* src/abg-leaf-reporter.cc (leaf_reporter::report): In the
	class_or_union_diff overload, add a terminating new line after
	reporting a declaration-only <-> definition difference.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-06-16 15:57:31 +02:00
Giuliano Procida
29de666641 abg-writer: Add support for stable hash type ids.
The type ids currently emitted by the XML writer are simply type-id-1,
type-id-2 etc. Additions or removals of types early in this sequence
result in cascading changes to many other XML elements.

This commit adds support for stable type ids in the form of hashes of
libabigail's internal type names. On fairly rare occasions (typically
involving unnamed types), the names of two distinct types can be the
same. In any case, if there is a hash collision the XML writer will
find the next unused id and so preserve uniqueness.

Diffs between large XML files produced using --type-id-style hash will
be much smaller and easier to review.

This also commit adds some test cases to verify that the hashing is
actually stable across architectures.

	* doc/manuals/abidw.rst: Replace stray documentation of
	--named-type-ids with documention of new --type-id-style
	option.
	* include/abg-writer.h (type_id_style_kind): Add new enum.
	(set_type_id_style): Add new write_context setter.
	(set_common_options): Set type id style in write context.
	* include/abg-hash.h (fnv_hash): Declare new 32-bit FNV-1a
        hash function in abigail::hashing namespace.
	* src/abg-hash.h (fnv_hash): Define new 32-bit FNV-1a hash
        function in abigail::hashing namespace.
	* src/abg-writer.cc (write_context): Add m_type_id_style
        member to record type style to use, defaulting to
        SEQUENCE_TYPE_ID_STYLE; add m_used_type_id_hashes to record
        already-used hashes.
	(write_context::get_type_id_style): Add new getter.
	(write_context::set_type_id_style): Add new setter.
	(get_id_for_type): Add support for HASH_TYPE_ID_STYLE style.
	(set_type_id_style): Add new helper function.
	* tools/abidw.cc (options): Add type_id_style member.
	(display_usage): Add description of --type-id-style option.
	(parse_command_line): Parse --type-id-style option.
	* tests/data/Makefile.am: Add new hash type id ABI files.
	* tests/test-read-dwarf.cc: (InOutSpec): Add type_id_style
	member.
	(in_out_specs): Set type_id_style to SEQUENCE_TYPE_ID_STYLE in
        existing test specifications. Duplicate first 9 test cases
        with type_id_style set to HASH_TYPE_ID_STYLE.
	* tests/data/test-read-dwarf/test0.hash.abi: New ABI XML file
	with hash type ids.
	* tests/data/test-read-dwarf/test1.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test2.so.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test3.so.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test4.so.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test5.o.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test6.so.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test7.so.hash.abi: Ditto.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi:
	Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-06-16 10:13:01 +02:00
Giuliano Procida
660605728f Eliminate non-ASCII characters.
There are few non-ASCII characters in various code comments. A few are
typos and the rest have obvious ASCII equivalents. This commit
replaces them all with ASCII characters.

	* include/abg-diff-utils.h: Replace "’’" with "'".
	* src/abg-elf-helpers.cc: Replace "⋅" with ".".
	* src/abg-ini.cc: Replace "@êef" with "@ref".
	* src/abg-ir.cc: Ditto.
	* src/abg-tools-utils.cc: Replace "–" with "-".

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-06-15 10:56:44 +02:00
Matthias Maennich
659e944266 dwarf-reader: get_die_source: always initialize return value
GCC9 with ABIGAIL_DEVEL=1 and ABIGAIL_DEBUG=1 set, regularly emits
-Werror=maybe-uninitialized for the values gathered by get_die_source.
As a counter measure, some of them were initialized before the call to
NO_DEBUG_INFO_DIE_SOURCE, but not all of them, leading to said warning.
In order to overcome this, let get_die_source always initialize the
source to NO_DEBUG_INFO_DIE_SOURCE and adjust the caller to consistently
not do that anymore. This solves the warning and maybe but unlikely (due
to the ABG_ASSERT) avoids some UB.

Changing the interface of get_die_source to return the source directly,
lead to the ability to initialize the value const and to defer the
assertion to the function itself. Some occurrences could be removed
entirely as the die_source was not used at all.

	* src/abg-dwarf-reader.cc
	(read_context::get_die_source): Always initialize die_source.
	(read_context::ContainerType::get_container): Fix
	initialization of die_source.
	(read_context::compute_canonical_die): Likewise.
	(read_context::get_canonical_die): Likewise.
	(read_context::get_or_compute_canonical_die): Likewise.
	(read_context::associate_die_to_decl): Likewise.
	(read_context::set_canonical_die_offset): Likewise.
	(read_context::schedule_type_for_late_canonicalization): Likewise.
	(read_context::compare_dies): Likewise.
	(read_context::get_parent_die): Likewise.
	(read_context::get_scope_for_die): Likewise.
	(read_context::add_or_update_union_type): Likewise.
	(read_context::maybe_canonicalize_type): Likewise.
	(read_context::build_ir_node_from_die): Likewise.

Signed-off-by: Matthias Maennich <maennich@google.com>
2020-06-15 10:00:54 +02:00
Matthias Maennich
4ef7e8c976 abipkgdiff: remove unused includes of elfutils/libdw.h and elf.h
Definitions from those headers are not actually used. Yet the includes
create unnecessary dependencies.

	* tools/abipkgdiff.cc: Drop unused includes.

Signed-off-by: Matthias Maennich <maennich@google.com>
2020-06-15 09:08:05 +02:00
Matthias Maennich
20b989fd3c abg-reporter: fully qualify std::string and std::ostream
In order to not unnecessarily pollute the abigail namespace and to avoid
ambiguity at compile time, fully qualify std::string and std::string.
This also resolves the issue that include/abg-reporter.h could not be
compiled standalone and therefore was broken as a public header. It
required a `using std::string` from a prior include.

	* include/abg-reporter.h (reporter_base::report) fully qualify
	std::string and std::ostream for all overloads.
	(default_reporter::report_local_typedef_changes): Likewise.
	(default_reporter::report_local_qualified_type_changes): Likewise.
	(default_reporter::report_local_reference_type_changes): Likewise.
	(default_reporter::report_local_function_type_changes): Likewise.
	(default_reporter::report): Likewise.
	(leaf_reporter::report_changes_from_diff_maps): Likewise.
	(leaf_reporter::report): Likewise.

Suggested-by: Mark Barolak <mbar@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
2020-06-11 15:10:44 +02:00
Giuliano Procida
2b4ff3c6cf Fix HARMLESS_SYMBOL_ALIAS_CHANGE_CATEGORY spelling
The enumerator HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY has a spelling
mistake in it. This changes fixes this and also corrects the spelling
of both this and HARMLESS_UNION_CHANGE_CATEORY when output.

	* include/abg-comparison.h (enum diff_category): Rename
	HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY enumerator to
	HARMLESS_SYMBOL_ALIAS_CHANGE_CATEGORY.
	* src/abg-comp-filter.cc (categorize_harmless_diff_node): Replace
	use of HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY enumerator with
	HARMLESS_SYMBOL_ALIAS_CHANGE_CATEGORY.
	* src/abg-comparison.cc (get_default_harmless_categories_bitmap):
	Replace use of HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY enumerator
	with HARMLESS_SYMBOL_ALIAS_CHANGE_CATEGORY.
	(operator<<): In the diff_category overload, replace use of
	HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY enumerator with
	HARMLESS_SYMBOL_ALIAS_CHANGE_CATEGORY and output correct
	spelling for both this and HARMLESS_UNION_CHANGE_CATEGORY.
	* tools/abicompat.cc (create_diff_context): Replace use of
	HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY enumerator with
	HARMLESS_SYMBOL_ALIAS_CHANGE_CATEGORY.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-06-11 10:06:04 +02:00
Matthias Maennich
6ffaef7a92 dwarf-reader: read_context: drop unused symbol versioning code
Since the symbol versioning helper code has been moved to elf_helpers in
commit  9815efe7a5 ("abg-elf-helpers: move some versioning helpers
from abg-dwarf-reader"), remove the leftover unused code from
read_context.

	* src/abg-dwarf-reader.cc
	(read_context::versym_section_): Delete.
	(read_context::verdef_section_): Delete.
	(read_context::verneed_section_): Delete.
	(read_context::symbol_versionning_sections_loaded_): Delete.
	(read_context::symbol_versionning_sections_found_): Delete.
	(read_context::initialize): Remove initializations of deleted members.
	(read_context::get_symbol_versionning_sections): Delete.
	(read_context::get_version_for_symbol): Delete.
	(read_context::lookup_elf_symbol_from_index): Use
	get_version_for_symbol provided by elf_helpers.

Signed-off-by: Matthias Maennich <maennich@google.com>
2020-06-11 10:02:58 +02:00
Matthias Maennich
cd5fdfe1b6 dwarf-reader: Remove unused code
Cleanup code that is never used to reduce overall compiled code and
complexity. Some are leftovers from prior refactorings, some are unused
overloads where the more suitable overload is still left.

	* src/abg-dwarf-reader.cc
	(lookup_public_variable_symbol_from_elf): Delete.
	(read_context::bss_section_): Delete.
	(read_context::text_section_): Delete.
	(read_context::rodata_section_): Delete.
	(read_context::data_section_): Delete.
	(read_context::data1_section_): Delete.
	(read_context::initialize): Remove initializations of deleted members.
	(read_context::options): Delete.
	(read_context::bss_section): Delete.
	(read_context::text_section): Delete.
	(read_context::rodata_section): Delete.
	(read_context::data_section): Delete.
	(read_context::data1_section): Delete.
	(read_context::get_elf_file_type): Delete.
	(read_context::lookup_symbol_from_elf): Delete.
	(read_context::lookup_public_variable_symbol_from_elf): Delete.
	(read_context::fun_addr_sym_map_sptr): Delete.
	(read_context::fun_addr_sym_map): Delete.
	(read_context::get_data_section_for_variable_address): Delete.
	(read_context::suppression_matches_function_sym_name): Delete.
	(read_context::suppression_matches_function_name): Delete.
	(read_context::suppression_matches_type_name): Delete.

Signed-off-by: Matthias Maennich <maennich@google.com>
2020-06-11 10:02:58 +02:00
Dodji Seketeli
7da00ff4b7 abigail.m4: Fix copyright notice
I wrote this file and added it to the repository in the commit:

    e4fefbdb Allow autoconf-based clients to detect the library

But then I added the wrong copyright notice back then.  Fixed thus.

	* abigail.m4: Mention Red Hat in the copyright and myself as author.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-29 18:11:10 +02:00
Matthias Maennich
72eb3fe482 tests: Add kernel symtab test suite
Add (Catch based) test suite to test kernel symbol table (ksymtab)
reading through the result persisted in abigail::corpus.

The test cases are created through simple kernel module C source files
targeting the desired properties ((gpl) exported / local functions /
variables). The kernel binaries are built without debug information to
keep them reasonably small and reproducible. That is just enough
sufficient to analyze ksymtabs. The Makefile that comes with them
recreates the test cases from the sources, given a kernel source tree
with the appropriate version, e.g.

   make KDIR=/path/to/4.14

This covers ksymtab reading and ensuring we detect the kernel binary
correctly. The kernel versions are selected based on features introduced
into the Linux kernel that affect the ksymtab representation.

 - Linux v4.14 - reasonably old kernel to start with (actually v4.14.180)
 - Linux v4.19 - first version having position relative relocations
		 (PREL) in ksymtab entries on some platforms
		 (actually v4.19.123)
 - Linux v5.4  - first version having symbol namespaces (actually v5.4.41)
 - Linux v5.6  - latest released stable kernel as of writing (actually v5.6.13)

	* tests/data/Makefile.am: add new test data for runtestsymtab
	* tests/data/test-symtab/kernel-4.14/Makefile: New test case makefile.
	* tests/data/test-symtab/kernel-4.14/empty.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_function.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_variable_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/empty.ko: New test data.
	* tests/data/test-symtab/kernel-4.14/one_of_each.ko: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_function.ko: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_function_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_variable.ko: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_variable_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/Makefile: New test case makefile.
	* tests/data/test-symtab/kernel-4.19/empty.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_function.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_variable_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/empty.ko: New test data.
	* tests/data/test-symtab/kernel-4.19/one_of_each.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_function.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_function_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_variable.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_variable_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/Makefile: New test case makefile.
	* tests/data/test-symtab/kernel-5.4/empty.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_function.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_variable_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/empty.ko: New test data.
	* tests/data/test-symtab/kernel-5.4/one_of_each.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_function.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_function_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_variable.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_variable_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/Makefile: New test case makefile.
	* tests/data/test-symtab/kernel-5.6/empty.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_function.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_variable_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/empty.ko: New test data.
	* tests/data/test-symtab/kernel-5.6/one_of_each.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_function.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_function_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_variable.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_variable_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel/Makefile: New test case source file.
	* tests/data/test-symtab/kernel/empty.c: Likewise.
	* tests/data/test-symtab/kernel/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel/single_function.c: Likewise.
	* tests/data/test-symtab/kernel/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel/single_variable_gpl.c: Likewise.
	* tests/test-symtab.cc: New test case to test kernel symtabs.

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-27 11:00:51 +02:00
Matthias Maennich
2a79ab78f4 tests: Add symtab test suite
Add (Catch based) test suite to test symbol table reading through the
result persisted in abigail::corpus.

The test cases are created through simple C source files targeting the
desired properties (having an undefined/export function or both). The
Makefile that comes with them recreates the test cases from the sources.

This covers reading sorted_(undefined_)var|fun_symbols as well as the
corresponding symbols maps accessible through the accessors of
abigail::corpus.

	* tests/Makefile.am: add new test runtestsymtab
	* tests/data/Makefile.am: add new test data for runtestsymtab
	* tests/data/test-symtab/Makefile: Add this to build the binaries
	below from their source code.
	* tests/data/test-symtab/basic/empty.c: New test case source.
	* tests/data/test-symtab/basic/link_against_me.c: Likewise.
	* tests/data/test-symtab/basic/no_debug_info.c: Likewise.
	* tests/data/test-symtab/basic/one_function_one_variable.c: Likewise.
	* tests/data/test-symtab/basic/one_function_one_variable_undefined.c: Likewise.
	* tests/data/test-symtab/basic/single_function.c: Likewise.
	* tests/data/test-symtab/basic/single_undefined_function.c: Likewise.
	* tests/data/test-symtab/basic/single_undefined_variable.c: Likewise.
	* tests/data/test-symtab/basic/single_variable.c: Likewise.
	* tests/data/test-symtab/basic/empty.so: New test data, built from
	the Makefile above.
	* tests/data/test-symtab/basic/link_against_me.so: Likewise.
	* tests/data/test-symtab/basic/no_debug_info.so: Likewise.
	* tests/data/test-symtab/basic/one_function_one_variable.so: Likewise.
	* tests/data/test-symtab/basic/one_function_one_variable_undefined.so: Likewise.
	* tests/data/test-symtab/basic/single_function.so: Likewise.
	* tests/data/test-symtab/basic/single_undefined_function.so: Likewise.
	* tests/data/test-symtab/basic/single_undefined_variable.so: Likewise.
	* tests/data/test-symtab/basic/single_variable.so: Likewise.
	* tests/test-symtab.cc: New test driver.

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-27 11:00:51 +02:00
Dodji Seketeli
e8bf5b803c Bug 25989 - type_topo_comp doesn't meet irreflexive requirements
When emitting abixml types inside a given scope are sorted
topologically.  Types that don't have source definition location
information are sorted lexicographically.

There are certain types however that need more careful consideration.

Those are empty-qualified types.  That is, qualified types (like
cv-qualified types) that carry no qualifier.  The patch explains
in-extenso in comments where those types come from.  You can also look
at the comments of the function maybe_strip_qualification for even
more context.

Simply put, an empty qualified type like 'NONE reference type' equals it's
non-qualified variant 'reference type'.

During the topological sorting, we chose to have the empty-qualified
variant "come before" (i.e, be "less than") the non-qualified variant.
This is alright.

The bug however is that we failed to handle the case were we are
looking at two empty-qualified types that are equal.  In that case, of
course, they are meant to be topologically equivalent.

Fixed thus.

	* src/abg-ir.cc (type_topo_comp::operator()): In the comparison
	operator consider two equivalent empty-qualified types as being
	topologically equivalent.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-19 12:11:27 +02:00
Dodji Seketeli
5eb4d7627a Bug 25661 - Support data member replacement by anonymous data member
We ought to detect when a data member is replaced by an anonymous data
member in a way that doesn't change the ABI in an incompatible way,
especially when that change is non equivocal.

For instance, consider this ABI-visible struct:

    struct S
    {
      int a;
    };

Now, consider that it's changed into:

    struct S
    {
      union
      {
	int a;
	char b;
      };
    };

Stricto sensu, the bit-layout of struct S doesn't change and so that
change isn't ABI-incompatible.

The current version of libabigail however flags that change as a
/potential/ issue and asks the user for further review.  It appears
that this class of changes is frequent enough to be annoying,
especially in semi-automatic ABI compliance checking setups where we
want the least possible "false positives".

This patch detects that kind of change patterns where a data member is
replaced by an anonymous data member in a benign way, in terms of ABI.

So now let's look at a more complicated example where an ABI-visible
type looks like:

struct S
{
  int a;
  int b;
  int c;
};

Now suppose that type was changed into:

struct S
{
  union
  {
    int tag[3];
    struct
    {
      int a;
      int b;
      int c;
    };
  };
};

The patch allows abidiff to recognise that kind of pattern, filter out
the detected change and report by default that the two binaries are
ABI compatible.

Here are the output that we'd get:

$ abidiff test-v0.o test-v1.o
Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added function
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

When asked to show the detailed of the filtered out changes, we get:

$ abidiff --harmless test-v0.o test-v1.o
Functions changes summary: 0 Removed, 1 Changed, 0 Added function
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

1 function with some indirect sub-type change:

  [C] 'function void foo(S*)' at test-v1.cc:18:1 has some indirect sub-type changes:
    parameter 1 of type 'S*' has sub-type changes:
      in pointed to type 'struct S' at test-v1.cc:1:1:
        type size hasn't changed
        data members 'S::a', 'S::b', 'S::c' were replaced by anonymous data member:
          'union {int tag[3]; struct {int a; int b; int c;};}'

And using the leaf-node reporter, that would give:

$ abidiff --leaf-changes-only --harmless test-v0.o test-v1.o
Leaf changes summary: 1 artifact changed
Changed leaf types summary: 1 leaf type changed
Removed/Changed/Added functions summary: 0 Removed, 0 Changed, 0 Added function
Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable

'struct S at test-v0.cc:1:1' changed:
  type size hasn't changed
  data members 'S::a', 'S::b', 'S::c' were replaced by anonymous data member:
    'union {int tag[3]; struct {int a; int b; int c;};}'

	* include/abg-comp-filter.h (has_data_member_replaced_by_anon_dm):
	Declare new function.
	* include/abg-comparison.h (changed_var_sptr)
	(changed_var_sptrs_type): Declare new typedefs.
	(HARMLESS_DATA_MEMBER_CHANGE_CATEGORY): Add a new enumerator to
	the diff_category enum.
	(EVERYTHING_CATEGORY): In the diff_category, adjust this
	enumerator to OR the new HARMLESS_DATA_MEMBER_CHANGE_CATEGORY into
	it.
	(SUPPRESSED_CATEGORY, PRIVATE_TYPE_CATEGORY)
	(SIZE_OR_OFFSET_CHANGE_CATEGORY, VIRTUAL_MEMBER_CHANGE_CATEGORY)
	(CLASS_DECL_ONLY_DEF_CHANGE_CATEGORY)
	(FN_PARM_TYPE_TOP_CV_CHANGE_CATEGORY)
	(FN_RETURN_TYPE_CV_CHANGE_CATEGORY, VAR_TYPE_CV_CHANGE_CATEGORY)
	(VOID_PTR_TO_PTR_CHANGE_CATEGORY)
	(BENIGN_INFINITE_ARRAY_CHANGE_CATEGORY): Adjust the value of these
	enumerators of the diff_category enum.
	(class_or_union_diff::{data_members_replaced_by_adms,
	ordered_data_members_replaced_by_adms}): Declare new member
	functions.
	* include/abg-fwd.h (var_decl_wptr): Declare new typedef.
	(get_next_data_member, get_first_non_anonymous_data_member)
	(find_data_member_from_anonymous_data_member)
	(get_absolute_data_member_offset): Declare new functions.
	* include/abg-ir.h (struct anonymous_dm_hash): Declare new type.
	(anonymous_data_member_sptr_set_type): Declare new typedef.
	(class decl_base): Befriend class class_or_union.
	(class dm_context_rel): Pimpl-ify this class.
	(dm_context_rel::{g,s}et_anonymous_data_member_types): Declare new
	member functions.
	(var_decl::get_anon_dm_reliable_name): Declare new member
	function.
	(class var_decl): Make get_absolute_data_member_offset,
	get_absolute_data_member_offset be friends of this.
	(class_or_union::maybe_fixup_members_of_anon_data_member): Declare
	new protected member function.
	* src/abg-comp-filter.cc (has_data_member_replaced_by_anon_dm):
	Define new function.
	(categorize_harmless_diff_node): Use the above.
	* src/abg-comparison-priv.h
	(class_or_union_diff::priv::{dms_replaced_by_adms_,
	changed_var_sptrs_type dms_replaced_by_adms_ordered_}): Add new
	data members.
	(data_member_comp::compare_data_members): Factorize this out of ...
	(data_member_comp::operator()(decl_base_sptr&, decl_base_sptr&)):
	... this.
	(data_member_comp::operator()(changed_var_sptr&,
	changed_var_sptr&)): Add new member function.
	(sort_changed_data_members): Declare ...
	* src/abg-comparison.cc (sort_changed_data_members): ... new
	function.
	(get_default_harmless_categories_bitmap): Adjust to take the new
	abigail::comparison::HARMLESS_DATA_MEMBER_CHANGE_CATEGORY into
	account.
	(operator<<(ostream& o, diff_category c)): Likewise.
	(class_or_union_diff::ensure_lookup_tables_populated): Handle
	Handle the insertion of anonymous data members to replace existing
	data members.
	(class_or_union_diff::{data_members_replaced_by_adms,
	ordered_data_members_replaced_by_adms}): Define new accessors.
	(suppression_categorization_visitor::visit_end): Propagate the
	SUPPRESSION_CATEGORIZATION_VISITOR from changes to the type of the
	data member if the data member doesn't have real local changes.
	* src/abg-default-reporter.cc (default_reporter::report): Report
	about anonymous data members that replace data members.
	* src/abg-ir.cc (struct dm_context_rel::priv): Define new data
	structure.
	(dm_context_rel::{dm_context_rel, get_is_laid_out,
	set_is_laid_out, get_offset_in_bits, set_offset_in_bits,
	operator==, operator!=, get_anonymous_data_member,
	set_anonymous_data_member}): Define the member functions here as
	they are not inline anymore.
	(class_or_union::maybe_fixup_members_of_anon_data_member): Define
	new member function.
	(class_or_union::add_data_member): Use it.
	(get_first_non_anonymous_data_member, get_next_data_member)
	(get_absolute_data_member_offset)
	(find_data_member_from_anonymous_data_member): Define new
	functions.
	* src/abg-reporter-priv.h
	(maybe_report_data_members_replaced_by_anon_dm): Declare ...
	* src/abg-reporter-priv.cc
	(maybe_report_data_members_replaced_by_anon_dm): ... new function.
	* src/abg-leaf-reporter.cc (leaf_reporter::report): Report data
	members replaced by anonymous data members.
	* tests/data/test-diff-filter/test-PR25661-[1-6]-report-[1-4].txt: New
	test reference outputs.
	* tests/data/test-diff-filter/test-PR25661-[1-6]-v{0,1}.c: Test
	source code files.
	* tests/data/test-diff-filter/test-PR25661-[1-6]-v{0,1}.o: Test
	binary input files.
	* tests/data/Makefile.am: Add the new test files above to source
	distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the binary test
	inputs above to this test harness.
	* tests/data/test-diff-dwarf/test45-anon-dm-change-report-0.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 13:42:50 +02:00
Dodji Seketeli
88fcbfeced dwarf-reader: support several anonymous data members in a given class
At the moment, if a class has more than one anonymous data member, we
are just keeping the first one and dropping the others.

This patch fixes that.

Now that there is the possibility of having several anonymous data
members in a given class we need to be able to name them correctly, to
tell them apart.  That means we cannot use the name returned by
var_decl::get_name() as that name is empty for an anonymous data
member.  This patch thus introduces a new method
var_decl::get_anon_dm_reliable_name() which returns a name that is
reliable (non-empty) even when the var_decl designates an anonymous
data member.  Note that there are many situations where we still need
to have var_decl::get_name() behave like it used to, so we can't make
it invariably return what var_decl::get_anon_dm_reliable_name()
returns today.

	* include/abg-ir.h (class_or_union::find_anonymous_data_member):
	Declare a new member function.
	(class_or_union::find_data_member): Declare a new overload.
	(var_decl::get_anon_dm_reliable_name): Declare new member
	function.
	* src/abg-ir.cc (var_decl::get_pretty_representation): Make this
	work on a var_decl is going to be used to represent an anonymous
	data member even before the var_decl has been added to its finale
	scope.  This is useful to make class_or_union::find_data_member
	work on a var_decl that is to be used as an anonymous data member.
	(var_decl::get_anon_dm_reliable_name): Define new member function.
	(class_or_union::find_data_member): In the existing overload that
	takes a string, look for the named data member inside the
	anonymous data members.  Define a new overload that takes a
	var_decl_sptr, to look for anonymous data members.
	(class_or_union::find_anonymous_data_member): Define a new member
	function.
	(lookup_data_member): Use the existing
	class_or_union::find_data_member.
	* src/abg-reader.cc: (build_class_decl): Use the full anonymous
	variable for lookup, rather than its name which is empty and will
	thus give false positives.
	* src/abg-dwarf-reader.cc (add_or_update_class_type): Likewise.
	* src/abg-comparison.cc
	(class_or_union_diff::ensure_lookup_tables_populated): Name
	anonymous data members properly - as opposed to wrongly using
	their empty name.
	* src/abg-reporter-priv.cc (represent): In the overload for
	var_diff_sptr, make sure that changes to the /type/ of a variable
	declaration are always reported.
	* tests/data/test-abidiff-exit/test-member-size-report0.txt:
	Adjust as we now emit more detailed changes about anonymous data
	members.
	* tests/data/test-abidiff-exit/test-member-size-report1.txt:
	Likewise.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi: Adjust
	to reflect the fact that a class can now have several anonymous
	data members.
	* tests/data/test-diff-dwarf-abixml/PR25409-librte_bus_dpaa.so.20.0.abi:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt:
	Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 13:42:50 +02:00