Commit Graph

134 Commits

Author SHA1 Message Date
Dodji Seketeli
610d87c29b Represent undefined corpus interfaces to analyze app compatibility
In the text below, the term interface means the "declaration of either
a function or a global variable".

To analyze the compatibility between an application and a dependent
library, one has essentially to analyze the interfaces of the
application that have undefined symbols (aka undefined interfaces from
the application) and see how they relate to the same interfaces coming
from the library but with symbols that are defined and exported from
the library (aka defined/exported interfaces from the library).

An interface that is undefined in the application and defined in the
library is an interface that the application consumes from the
library.

In other words an undefined interface from an application is an
interface that the application expects and an interface that is
exported by a library is an interface that the library provides.

If comparing the expected interface against the provided interface
yields a meaningful difference, then that might mean there is an
incompatibility between the application and the library on that
interface.

This patch uses this scheme to re-implement the weak mode of ABI
compatibility between an application and a library.

The patch adds the concept of undefined functions and variables to the
ABI corpus.  Then it teaches the DWARF reader how to construct the IR
for these undefined interfaces.  Then it revisits the weak mode of
operation of abicompat to make it compare the interfaces expected from
the application against the corresponding interfaces provided by
library.  The patch also teaches the weak mode abicompat how to detect
incompatibilities between the interfaces that plugin expects and the
interfaces provided by the application.

This patch makes the CTF front-end construct undefined interfaces.  A
subsequent patch is needed to construct undefined interfaces from the
BTF front-end however.

	* include/abg-corpus.h (corpus::{lookup_variable,
	get_undefined_functions, get_undefined_variables}): Declare new
	member functions.
	(corpus::exported_decls_builder::maybe_add_{fn,var}_to_exported_fns):
	Make this return a boolean.
	* include/abg-fe-iface.h (fe_iface::options_type): Add a new
	load_undefined_interfaces enumerator.
	(fe_iface::add_fn_to_exported_or_undefined_decls): Rename
	maybe_add_fn_to_exported_decls into this.
	(fe_iface::add_var_to_exported_or_undefined_decls): Rename
	maybe_add_var_to_exported_decls into this.
	* src/abg-btf-reader.cc (reader::build_ir_node_from_btf_type):
	Adjust call to maybe_add_fn_to_exported_decls as
	add_fn_to_exported_or_undefined_decls.  Similarly, adjust call to
	maybe_add_var_to_exported_decls as
	add_var_to_exported_or_undefined_decls.
	* src/abg-corpus-priv.h (corpus::priv::undefined_{fns,vars}): Add
	new member variables.
	* src/abg-corpus.cc
	(corpus::exported_decls_builder::maybe_add_{fn,var}_to_exported_fns):
	Return a bool iff the decl was added to the set of exported decls.
	(corpus::{lookup_variable, get_undefined_functions,
	get_undefined_variables}): Define new member functions.
	(corpus::sort_{functions,variables}): Sort the undefined decls
	too.
	* (corpus::lookup_{function,variable}_symbol): Lookup the symbol
	also among undefined symbols, not just among defined symbols.
	* src/abg-ctf-reader.cc (reader::process_ctf_archive): Adjust call
	to maybe_add_fn_to_exported_decls as
	add_fn_to_exported_or_undefined_decls.  Similarly, adjust call to
	maybe_add_var_to_exported_decls as
	add_var_to_exported_or_undefined_decls. Also, sort functions &
	variables in the corpus.
	* src/abg-dwarf-reader.cc (die_name_and_linkage_name): Define new
	static function.
	(reader::fixup_functions_with_no_symbols): Adjust call to
	maybe_add_fn_to_exported_decls as
	add_fn_to_exported_or_undefined_decls.
	(reader::{is_decl_die_with_undefined_symbol,
	load_undefined_interfaces}): Define new member functions.
	(build_translation_unit_and_add_to_ir): Analyze DIEs of interfaces
	that have undefined symbols if we were asked to load undefined
	interfaces.
	(variable_is_suppressed): Add a boolean parameter to tell if the
	var is decl-only.  Use that decl-only flag to determine if the
	variable is suppressed.  A non-member decl-only variable won't be
	suppressed if we were asked to load undefined interfaces.
	(build_or_get_var_decl_if_not_suppressed): Add a boolean parameter
	to tell if the var is decl-only.
	(potential_member_fn_should_be_dropped): A potential non-virtual
	member function with no symbol is now dropped on the floor
	regardless of it has a mangled name or not.
	(build_var_decl): If the var has an undefined symbol, then set
	that symbol.
	(build_function_decl): If the function has an undefined symbol,
	then set that symbol.
	(build_ir_node_from_die): Add a var or function with undefined
	symbol to the set of undefined vars or functions of the current
	corpus.
	* src/abg-fe-iface.cc
	(fe_iface::add_fn_to_exported_or_undefined_decls): Renamed
	fe_iface::maybe_add_fn_to_exported_decls into this.  If the
	function has an undefined symbol then add the function to the set
	of undefined functions.
	(fe_iface::add_var_to_exported_or_undefined_decls): Renamed
	fe_iface::maybe_add_var_to_exported_decls into this.  If the
	variable has an undefined symbol then add the variable to the set
	of undefined variables.
	* src/abg-ir.cc (elf_symbol::is_variable): Undefined symbol with
	type STT_NOTYPE are actually for undefined variables.
	(maybe_adjust_canonical_type): It's here, after type
	canonicalization that a member function is added to either the set
	of defined & exported functions, or to the set of functions with
	undefined symbols.
	* src/abg-reader.cc (build_function_decl, build_class_decl)
	(build_union_decl, handle_var_decl): Adjust.
	* src/abg-symtab-reader.cc
	(symtab::{lookup_undefined_function_symbol,
	lookup_undefined_variable_symbol, function_symbol_is_undefined,
	variable_symbol_is_undefined,
	collect_undefined_fns_and_vars_linkage_names}): Define new member
	functions.
	(symtab::symtab): Initialize the new
	cached_undefined_symbol_names_ data member.
	* src/abg-symtab-reader.h
	(symtab::{lookup_undefined_function_symbol,
	lookup_undefined_variable_symbol, function_symbol_is_undefined,
	variable_symbol_is_undefined,
	collect_undefined_fns_and_vars_linkage_names}): Declare new member
	functions.
	(symtab::{undefined_variable_linkage_names_,
	cached_undefined_symbol_names_}): Define new data members.
	(symtab::load_): Consider undefined symbol of type STT_NOTYPE as
	being undefined global variables.  It's what I am seeing in ELF
	binaries.
	* src/abg-symtab-reader.h
	(symtab::{lookup_undefined_function_symbol,
	lookup_undefined_variable_symbol, function_symbol_is_undefined,
	variable_symbol_is_undefined}): Declare new member functions.
	(symtab::{undefined_function_linkage_names_,
	undefined_variable_linkage_names_}): Define new member variables.
	* src/abg-writer.cc (write_var_decl, write_function_decl): Emit a
	reference to a symbol only when the symbol is defined.
	* tools/abicompat.cc (report_function_changes)
	(report_variable_changes)
	(compare_expected_against_provided_functions)
	(compare_expected_against_provided_variables): Define new static
	functions.
	(perform_compat_check_in_weak_mode): Use the new static functions
	above. Compare interfaces expected by the application corpus
	against interfaces provided by the library.  Report the changes.
	Do that in the reverse direction as well.
	(read_corpus): Instruct the corpus reader to load the set of
	undefined interfaces too.
	* tests/data/test-abicompat/test6-var-changed-app: Remove file.
	* tests/data/test-abicompat/test6-var-changed-app.cc: Likewise.
	* tests/data/test-abicompat/libtest6-undefined-var.so: Add new
	binary input file.
	* tests/data/test-abicompat/test6-undefined-var.cc: Add sourcefile
	for the binary input file above.
	* tests/data/test-abicompat/test6-var-changed-report-2.txt: New
	reference output file.
	* tests/data/Makefile.am: Update the list of distributed files
	accordingly.
	* tests/data/test-abicompat/libtest5-fn-changed-libapp-v0.so:
	Adjust.
	* tests/data/test-abicompat/libtest5-fn-changed-libapp-v1.so:
	Likewise.
	* tests/data/test-abicompat/libtest6-var-changed-libapp-v0.so:
	Likewise.
	* tests/data/test-abicompat/libtest6-var-changed-libapp-v1.so:
	Likewise.
	* tests/data/test-abicompat/libtest7-fn-changed-libapp-v0.so:
	Likewise.
	* tests/data/test-abicompat/libtest7-fn-changed-libapp-v1.so:
	Likewise.
	* tests/data/test-abicompat/libtest8-fn-changed-libapp-v0.so:
	Likewise.
	* tests/data/test-abicompat/libtest8-fn-changed-libapp-v1.so:
	Likewise.
	* tests/data/test-abicompat/libtest9-fn-changed-v0.so: Likewise.
	* tests/data/test-abicompat/libtest9-fn-changed-v1.so: Likewise.
	* tests/data/test-abicompat/test5-fn-changed-app: Likewise.
	* tests/data/test-abicompat/test6-var-changed-libapp-v0.cc:
	Likewise.
	* tests/data/test-abicompat/test6-var-changed-libapp-v1.cc:
	Likewise.
	* tests/data/test-abicompat/test6-var-changed-report-0.txt:
	Likewise.
	* tests/data/test-abicompat/test6-var-changed-report-1.txt:
	Likewise.
	* tests/data/test-abicompat/test7-fn-changed-app: Likewise.
	* tests/data/test-abicompat/test7-fn-changed-report-1.txt:
	Likewise.
	* tests/data/test-abicompat/test7-fn-changed-report-2.txt:
	Likewise.
	* tests/data/test-abicompat/test8-fn-changed-app: Likewise.
	* tests/data/test-abicompat/test8-fn-changed-libapp-v1.c:
	Likewise.
	* tests/data/test-abicompat/test9-fn-changed-app: Likewise.
	* tests/data/test-abicompat/test9-fn-changed-app.cc: Likewise.
	* tests/data/test-annotate/libtest23.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.ab: Likewise.i
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test2.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi:
	Likewise.
	* tests/data/test-diff-pkg/dbus-glib-0.104-3.fc23.x86_64--dbus-glib-0.104-3.fc23.armv7hl-report-0.txt:
	Likewise.
	* 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:
	Likewise.
	* tests/data/test-fedabipkgdiff/test0-from-fc20-to-fc23-dbus-glib-report-0.txt:
	Likewise.
	* tests/data/test-fedabipkgdiff/test2-dbus-glib-0.100.2-2.fc20--dbus-glib-0.106-1.fc23-report-0.txt:
	Likewise.
	* tests/data/test-fedabipkgdiff/test3-dbus-glib-0.100.2-2.fc20.i686--dbus-glib-0.106-1.fc23.i686-report-0.txt:
	Likewise.
	* tests/data/test-fedabipkgdiff/vte291-0.39.1-1.fc22.x86_64--vte291-0.39.90-1.fc22.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR26261/PR26261-exe.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test1.hash.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/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/test2.so.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.hash.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/test8-qualified-this-pointer.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi:
	Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.
	* tests/test-abicompat.cc (in_out_specs): Adjust.
	* tests/test-read-ctf.cc (test_task_ctf::perform): Do not load
	undefined interfaces, by default.
	* tests/test-symtab.cc (Symtab::SimpleSymtabs)
	(Symtab::SymtabWithWhitelist, Symtab::AliasedFunctionSymbols):
	Adjust the expected undefined variable symbols counts.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-03-14 16:26:54 +01:00
Dodji Seketeli
908f56e1b5 ir,dwarf-reader: Peel const-qualifier from const this pointers
In DWARF, it appears that the this pointer of a concrete instance of
method is sometimes represented as a const pointer, whereas the this
pointer of the abstract instance (or interface) of that same method
has the this pointer represented as a non-const pointer.  That
difference often causes some spurious const-ness change reports on the
this pointer when doing comparisons.

This patch thus trims of the const-qualifier off of the this pointer
of methods.

	* include/abg-fwd.h (is_const_qualified_type)
	(peel_const_qualified_type): Declare ...
	* src/abg-ir.cc (is_const_qualified_type)
	(peel_const_qualified_type): ... new functions.
	* src/abg-dwarf-reader.cc (build_function_type): Trim the const
	qualifier off of the this pointer representation if present.
	* tests/data/test-annotate/test1.abi: Adjust.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test2.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test6.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi:
	Likewise.
	* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi:
	Likewise.
	* tests/data/test-diff-dwarf/test0-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test28-vtable-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test29-vtable-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test30-vtable-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test31-vtable-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test36-ppc64-aliases-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test41-PR20476-hidden-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test5-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test8-report.txt: Likewise.
	* tests/data/test-diff-filter/test0-report.txt: Likewise.
	* tests/data/test-diff-filter/test01-report.txt: Likewise.
	* tests/data/test-diff-filter/test10-report.txt: Likewise.
	* tests/data/test-diff-filter/test13-report.txt: Likewise.
	* tests/data/test-diff-filter/test2-report.txt: Likewise.
	* tests/data/test-diff-filter/test28-redundant-and-filtered-children-nodes-report-1.txt:
	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/test30-pr18904-rvalueref-report2.txt:
	Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test9-report.txt: Likewise.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64--libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-10.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-12.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-14.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-16.txt:
	Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-4.txt: Likewise.
	* tests/data/test-diff-suppr/test31-report-1.txt: Likewise.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test1.hash.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/test2.so.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.hash.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.
	* tests/data/test-read-dwarf/test6.so.abi: Likewise.
	* tests/data/test-read-dwarf/test6.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-03-06 14:02:55 +01:00
Dodji Seketeli
fabfb912d5 tests/data/test-diff-pkg: Update dpkg related reference output
The previous patch needed the update of a lot of reference tests.  I
didn't have dpkg installed on my development box so I missed updating
dpkg-related reference output.

	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64--libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64-report-0.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-03-02 16:30:23 +01:00
Dodji Seketeli
3ccfe46541 dwarf-reader: Fix DIE origin handling & scope getting
While looking at something else, I noticed that a number of times the
code to create the IR for function-decl was adding the function to the
wrong scope, especially for DIEs that had a chain of
DW_AT_abstract_origin *and* DW_AT_specification attributes.

Suppose we are looking at a DIE D that has a DW_AT_abstract_origin
attribute pointing to a DIE D'.  D' itself has a DW_AT_specification
that points to D''.  The scope of the function should be represented
by the scope DIE of D'', not the scope DIE of D'.  Unfortunately
build_ir_node_from_die was sometimes using the scope of D'.

This patch fixes that by introducing a new die_origin_die function
that returns the ultimate origin of a DIE.  In the case above, the
ultimate origin of D is D''.  die_origin_die is thus used by
get_scope_die and get_scope_for_die to get the correct scope of a DIE.
The code of build_ir_node_from_die that handles DW_TAG_subprogram DIEs
is thus simplified as get_scope_for_die now does the heavy lifting of
handling DW_AT_abstract_origin and DW_AT_specification.

The result is a simpler and easier to maintain build_ir_node_from_die
and hopefully a more correct one.  A lot of the ABIXML and the type
denomination in change reports of the test suite have been updated to
reflect the more accurate representation.

	* src/abg-dwarf-reader.cc (die_origin_die): New static function.
	(get_scope_die, get_scope_for_die): Use the new die_origin_die
	above.
	(build_ir_node_from_die): Don't handle DW_AT_abstract_origin and
	DW_AT_specification here.  In general, do not handle getting the
	scope.  Rather, just rely on get_scope_for_die.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Adjust.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test2.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test6.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi:
	Likewise.
	* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi:
	Likewise.
	* tests/data/test-diff-dwarf/test0-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test28-vtable-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test29-vtable-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test30-vtable-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test31-vtable-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test36-ppc64-aliases-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test41-PR20476-hidden-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test5-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test8-report.txt: Likewise.
	* tests/data/test-diff-filter/test0-report.txt: Likewise.
	* tests/data/test-diff-filter/test01-report.txt: Likewise.
	* tests/data/test-diff-filter/test10-report.txt: Likewise.
	* tests/data/test-diff-filter/test13-report.txt: Likewise.
	* tests/data/test-diff-filter/test2-report.txt: Likewise.
	* tests/data/test-diff-filter/test28-redundant-and-filtered-children-nodes-report-1.txt:
	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/test30-pr18904-rvalueref-report2.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test9-report.txt: Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-10.txt:
	Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-12.txt:
	Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-14.txt:
	Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-16.txt:
	Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-4.txt: Likewise.
	* tests/data/test-diff-suppr/test31-report-1.txt: Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test1.hash.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/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/test2.so.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.hash.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.
	* tests/data/test-read-dwarf/test6.so.abi: Likewise.
	* tests/data/test-read-dwarf/test6.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi:
	Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-03-01 14:22:49 +01:00
Dodji Seketeli
19d4131964 Improve type naming
There are a number of glitches when pretty-printing type names.

This is particularly true for derived types like pointer to functions,
array of pointer to functions and the likes.

For instance, we can see in
tests/data/test-abidiff-exit/PR30048-test-2-report-1.txt that a
function N that takes no parameter and returns a pointer to an array
of 7 int is pretty-printed as:

    int[7]* N()

That obviously doesn't respect the type naming rules of C or C++.

With this patch, function N is declared as:

    int(*N(void))[7]

To learn more about the impact of the patch on how types are
pretty-printed, you can look at the parts of the patch that are
adjustments to the expected output of the regression tests.

For instance, here is how the expected output of type pretty-printing
in tests/data/test-abidiff-exit/PR30048-test-2 is modified by this
patch:

    diff --git a/tests/data/test-abidiff-exit/PR30048-test-2-report-1.txt b/tests/data/test-abidiff-exit/PR30048-test-2-report-1.txt
    index 2650b5a0..7bbbc2e2 100644
    --- a/tests/data/test-abidiff-exit/PR30048-test-2-report-1.txt
    +++ b/tests/data/test-abidiff-exit/PR30048-test-2-report-1.txt
    @@ -3,22 +3,22 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

     7 functions with some indirect sub-type change:

    -  [C] 'function int[7]* N()' at PR30048-test-2-v0.cc:62:1 has some indirect sub-type changes:
    +  [C] 'function int(*N(void))[7]' at PR30048-test-2-v0.cc:62:1 has some indirect sub-type changes:
	 return type changed:
    -      entity changed from 'int[7]*' to 'int'
    +      entity changed from 'int(*)[7]' to 'int'
	   type size changed from 64 to 32 (in bits)

    -  [C] 'function int* O()' at PR30048-test-2-v0.cc:64:1 has some indirect sub-type changes:
    +  [C] 'function int* O(void)' at PR30048-test-2-v0.cc:64:1 has some indirect sub-type changes:
	 return type changed:
	   entity changed from 'int*' to 'int'
	   type size changed from 64 to 32 (in bits)

    -  [C] 'function int ()* P()' at PR30048-test-2-v0.cc:67:1 has some indirect sub-type changes:
    +  [C] 'function int (*P(void))(void)' at PR30048-test-2-v0.cc:67:1 has some indirect sub-type changes:
	 return type changed:
    -      entity changed from 'int ()*' to 'int'
    +      entity changed from 'int (*)(void)' to 'int'
	   type size changed from 64 to 32 (in bits)

Note that the change to the CTF test
tests/data/test-read-ctf/test9.o.abi is triggered by a change in the
sorting of types because types are sorted alphabetically.

All in all, this is clearly an overdue improvement to the type name
pretty-printing.

	* include/abg-fwd.h (is_npaf_type, is_pointer_to_function_type)
	(is_pointer_to_array_type, is_pointer_to_npaf_type): Declare new
	functions.
	(is_pointer_type, is_reference_type, is_array_type): Take a
	boolean parameter to look through qualifiers.
	* include/abg-ir.h (is_pointer_type): Do not make this function a
	friend of the type_or_decl_base class anymore.
	* src/abg-ir.cc (pointer_declaration_name, array_declaration_name)
	(stream_pretty_representation_of_fn_parms)
	(add_outer_pointer_to_fn_type_expr)
	(add_outer_pointer_to_array_type_expr): Define new static
	functions.
	(is_npaf_type, is_pointer_to_function_type)
	(is_pointer_to_array_type, is_pointer_to_npaf_type): Define new
	functions.
	(get_type_representation): Remove the overload for array_type_def.
	(get_function_type_name, get_method_type_name)
	(function_decl::get_pretty_representation_of_declarator): Use the
	new stream_pretty_representation_of_fn_parms.  This actually
	factorizes parameters pretty-printing by reusing
	stream_pretty_representation_of_fn_parms.
	(is_pointer_type, is_reference_type, is_array_type): Take a
	boolean parameter to look through qualifiers.
	(is_void_pointer_type): Use const where it's due.
	(pointer_type_def::get_qualified_name): Use the new
	pointer_declaration_name in lieu of the old and removed
	get_name_of_pointer_to_type.
	(array_type_def::{get_pretty_representation, get_qualified_name}):
	Use the new array_declaration_name instead of the old and removed
	get_type_representation.
	(var_decl::get_pretty_representation): Use the new
	array_declaration_name and pointer_declaration_name.
	(function_decl::get_pretty_representation): Use the new
	add_outer_pointer_to_array_type_expr, and
	add_outer_pointer_to_array_type_expr function to support the
	proper syntax for function returning pointers and arrays.
	(function_decl::parameter::get_pretty_representation): Fix the
	pretty-printing of each function parameter.
	* tests/data/test-abicompat/test0-fn-changed-report-0.txt: Adjust.
	* tests/data/test-abicompat/test0-fn-changed-report-2.txt:
	Likewise.
	* tests/data/test-abicompat/test1-fn-removed-report-0.txt:
	Likewise.
	* tests/data/test-abicompat/test3-fn-removed-report-0.txt:
	Likewise.
	* tests/data/test-abidiff-exit/PR30048-test-2-report-1.txt: Likewise.
	* tests/data/test-abidiff-exit/PR30048-test-report-0.txt: Likewise.
	* tests/data/test-abidiff-exit/PR30329/PR30329-report-1.txt: Likewise.
	* tests/data/test-abidiff-exit/PR30503/libsdl/libsdl-1.2.60-1.2.64-report.txt: Likewise.
	* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-1.txt: Likewise.
	* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-2.txt: Likewise.
	* tests/data/test-abidiff-exit/qualifier-typedef-array-report-1.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-fun-param-report.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-ld-2.28-210.so--ld-2.28-211.so.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-leaf-fun-type-report.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-leaf-more-report.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-leaf-peeling-report.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-leaf-stats-report.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-net-change-report0.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-net-change-report2.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test2-filtered-removed-fns-report0.txt:
	Likewise.
	* tests/data/test-abidiff/test-PR18791-report0.txt: Likewise.
	* tests/data/test-abidiff/test-crc-report-0-1.txt: Likewise.
	* tests/data/test-abidiff/test-crc-report-1-0.txt: Likewise.
	* tests/data/test-abidiff/test-crc-report-1-2.txt: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-annotate/test7.so.abi: Likewise.
	* tests/data/test-diff-dwarf/PR25058-liblttng-ctl-report-1.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test-23-diff-arch-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test18-alias-sym-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test19-soname-report-0.txt: Likewise.
	* tests/data/test-diff-dwarf/test24-added-fn-parms-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test32-fnptr-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test33-fnref-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test41-PR20476-hidden-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test5-report.txt: Likewise.
	* tests/data/test-diff-filter/test-PR26739-2-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test26-qualified-redundant-node-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test26-qualified-redundant-node-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test6-report.txt: Likewise.
	* tests/data/test-diff-filter/test7-report.txt: Likewise.
	* tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64--2.24.2-30.fc30.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/PR24690/PR24690-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64--libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/libxcrypt-4.1.1-6.el8.x86_64--libxcrypt-compat-4.4.18-3.el9.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-pkg-ctf/gmp-6.x.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg-ctf/test-rpm-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-report-3.txt:
	Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-report-5.txt:
	Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-report-7.txt:
	Likewise.
	* tests/data/test-diff-suppr/test15-suppr-added-fn-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test15-suppr-added-fn-report-2.txt:
	Likewise.
	* tests/data/test-diff-suppr/test15-suppr-added-fn-report-5.txt:
	Likewise.
	* tests/data/test-diff-suppr/test16-suppr-removed-fn-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test16-suppr-removed-fn-report-3.txt:
	Likewise.
	* tests/data/test-diff-suppr/test16-suppr-removed-fn-report-5.txt:
	Likewise.
	* tests/data/test-diff-suppr/test27-add-aliased-function-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test27-add-aliased-function-report-3.txt:
	Likewise.
	* tests/data/test-diff-suppr/test27-add-aliased-function-report-4.txt:
	Likewise.
	* tests/data/test-diff-suppr/test28-add-aliased-function-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test28-add-aliased-function-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test28-add-aliased-function-report-2.txt:
	Likewise.
	* tests/data/test-diff-suppr/test28-add-aliased-function-report-4.txt:
	Likewise.
	* tests/data/test-diff-suppr/test28-add-aliased-function-report-5.txt:
	Likewise.
	* tests/data/test-diff-suppr/test30-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test32-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test32-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test44-suppr-sym-name-not-regexp-report-1.txt:
	Likewise.
	* tests/data/test-fedabipkgdiff/vte291-0.39.1-1.fc22.x86_64--vte291-0.39.90-1.fc22.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-read-ctf/test9.o.abi: Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.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/test19-pr19023-libtcmalloc_and_profiler.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/test7.so.abi: Likewise.
	* tests/data/test-read-dwarf/test7.so.hash.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2023-12-01 15:43:53 +01:00
Dodji Seketeli
bad389f01a abipkgdiff: Avoid comparing binaries that are outside of the package
Some symlinks in some RPMs resolve to binaries outside of the package. In
those cases, avoid considering them.

	* src/abg-tools-utils.cc (maybe_get_symlink_target_file_path): Do
	not require that the file path points to a symlink.  A file path
	can point to a file that is not a symlink and yet the whole path
	can be in parent directory that is a symlink.  In this case,
	realpath will correctly resolve to the correct target file.
	* tools/abipkgdiff.cc (maybe_update_package_content): A path to a
	binary that is not inside the RPM (because a symlink resolved to a
	file outside of the RPM) should not be added to the set of
	binaries to be analyzed.
	* tests/data/test-diff-pkg/symlink-dir-test1-report1.txt: Add new
	test file.
	* tests/data/test-diff-pkg-ctf/symlink-dir-test1-report1.txt:
	Likewise.
	* tests/data/Makefile.am: Add new test file to source
	distribution.
	* tests/test-diff-pkg.cc (in_out_specs): for the
	data/test-diff-pkg/symlink-dir-test1/dir{1,2}/symlinks test, the
	root dir of the package is
	data/test-diff-pkg/symlink-dir-test1/dir{1,2}.  Use that to test
	that the symlinks are properly handled.  Also, use the
	data/test-diff-pkg/symlink-dir-test1/dir{1,2}/symlinks as a root
	of an alternative package for which the symlinks resolve outside
	the package, under
	data/test-diff-pkg/symlink-dir-test1/dir{1,2}/targets.  In this
	later case, the symlinked files should be ignored in the
	comparison.  Likewise for
	data/test-diff-pkg-ctf/symlink-dir-test1/dir1/symlinks.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2023-09-07 15:23:38 +02:00
Dodji Seketeli
5a6c04c8bd abipkgdiff: Don't use user-specific filesystem info in error msg
The recent patch "Bug rhbz#2182807 --  abipkgdiff crashes on missing debuginfo package"
inadvertently introduced user-specific filesystem information in error
messages, making tests/runtestdiffpkg be non-deterministic.  Fixed
thus.

	* tools/abipkgdiff.cc (get_pretty_printed_list_of_packages): Emit
	base names of packages, not the absolute filesystem path.
	* tests/data/test-diff-pkg/libxfce4ui-devel-4.12.1-8.fc27.ppc64-self-report-0.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2023-04-05 17:01:48 +02:00
Dodji Seketeli
ed205e0e79 Bug rhbz#2182807 -- abipkgdiff crashes on missing debuginfo package
When abipkgdiff is called with a debug info package that references an
alternate debug info file that is not found -- because debug info
package is missing from the command line -- the program aborts.  This
is because the libabigail library is further invoked by the tool with
debuginfo in an inconsistent state (missing alternate debug info).

Note however that abipkgdiff only emits an explanatory message when
invoked with the --verbose option.

This patch teaches abipkgdiff to emit explanatory messages when an
alternate debug info file is not found.  The message suggests that the
user adds the missing RPM package (which contains the alternate
missing debuginfo file) to the command line using the --d1/--d2
switches.

	* src/abg-fe-iface.cc (status_to_diagnostic_string): Remove the
	newline from the end of the returned diagnostic string.
	* tools/abipkgdiff.cc (get_pretty_printed_list_of_packages)
	(emit_alt_debug_info_not_found_error): Define new static
	functions.
	(compare, compare_to_self): Add an ostream& parameter as a
	destination of diagnostic messages.  If the
	abigail::fe_iface::STATUS_ALT_DEBUG_INFO_NOT_FOUND bit is set in
	the status code, emit the explanatory message to output stream
	associated to the current comparison task.  Remove the previous
	handling of this case.
	(compare_task::maybe_emit_pretty_error_message_to_output): Define
	new member function to get the output stream associated to the
	current task massage it and stick to result into the pretty output
	string to be emitted to the user in the end, namely the
	compare_task::pretty_output string data member.
	({compares, self_compare}_task::perform): Adjust this to call the
	new maybe_emit_pretty_error_message_to_output in case of error.
	* tests/data/test-diff-pkg/libxfce4ui-devel-4.12.1-8.fc27.ppc64-self-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/test-dbus-glib-0.80-3.fc12.x86_64-report-0.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2023-04-03 17:01:44 +02:00
Dodji Seketeli
82973c898a default-reporter: Fix source location in functions change report
While looking at something else, I realized that the default-reporter
mentions the source location of the new function in lieu of the old function
when reporting about a function change.  Fixed thus.

	* src/abg-default-reporter.cc (default_reporter::report): In the
	overload of function_decl, use the source location of the old
	function.
	* tests/data/test-abicompat/test0-fn-changed-report-2.txt: Adjust.
	* tests/data/test-abidiff-exit/qualifier-typedef-array-report-1.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-PR28316-report.txt: Likewise.
	* tests/data/test-abidiff-exit/test-decl-enum-report.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-decl-struct-report.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-fun-param-report.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-headers-dirs/test-headers-dir-report-2.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-loc-with-locs-report.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-member-size-report0.txt:
	Likewise.
	* tests/data/test-abidiff-exit/test-rhbz2114909-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/libtest45-basic-type-change-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test-PR24731-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test-PR25661-1-report-2.txt:
	Likewise.
	* tests/data/test-diff-filter/test-PR25661-2-report-2.txt:
	Likewise.
	* tests/data/test-diff-filter/test-PR25661-3-report-2.txt:
	Likewise.
	* tests/data/test-diff-filter/test-PR25661-4-report-2.txt:
	Likewise.
	* tests/data/test-diff-filter/test-PR25661-5-report-2.txt:
	Likewise.
	* tests/data/test-diff-filter/test-PR25661-6-report-3.txt:
	Likewise.
	* tests/data/test-diff-filter/test-PR25661-7-report-3.txt:
	Likewise.
	* tests/data/test-diff-filter/test-PR26739-2-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test-PR29387-report.txt: Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test36-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test37-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test39/test39-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test44-anonymous-data-member-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/dirpkg-3-report-2.txt: Likewise.
	* 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:
	Likewise.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.
	* tests/data/test-diff-pkg/symlink-dir-test1-report0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tarpkg-1-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/PR28073/PR28073-output-2.txt:
	Likewise.
	* tests/data/test-diff-suppr/libtest48-soname-abixml-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test30-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test41-enumerator-changes-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test42-negative-suppr-type-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test42-negative-suppr-type-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-0-1.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2023-02-10 13:15:27 +01:00
Dodji Seketeli
754364d5ca Fix spurious deleted/added virtual destructor change report
While looking at something else, I noticed this spurious change
report:

    1 member function deletion:
      'method virtual tbb::internal::concurrent_queue_base_v3::~concurrent_queue_base_v3(int)' at concurrent_queue.cpp:361:1
    1 member function insertion:
		'method virtual tbb::internal::concurrent_queue_base_v3::~concurrent_queue_base_v3(int)' at concurrent_queue.cpp:370:1

This is when running tests/runtestdiffpkg and the result is in
tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt.

To understand what is going on, one need to refer to the definitions
of the C++ ABI at
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#definitions.

When a class has a virtual destructor, historically, there might be 3
different and co-existing actual implementations of the destructors:
the D0, D1 and D2 destructors.  There might even be a D3 destructor,
actually.

In https://github.com/itanium-cxx-abi/cxx-abi/issues/73, one can see
that there might be new D4 and D5 destructors.  Each one of them might
replace the set of the D0,D1,D2 destructors.

So, in a new version of a binary, the virtual D4 destructor might
replace the previous ones, without it being an ABI issue.

The switch to the D4 virtual destructor is what libabigail is naively
reporting in the change report above.

This patch detects this kind of changes in the pipeline when the edit
script from the diff2 algorithm is interpreted for virtual member
functions and drops it on the floor.

	* src/abg-comparison.cc (find_virtual_dtor_in_map): Define new
	static function.
	(class_diff::ensure_lookup_tables_populated): If a virtual
	destructor is removed from the old binary version but is added to
	the new one (but through a different name), let's assume the
	virtual destructor is still there so there is no ABI issue
	from that point of view.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-11-30 17:12:32 +01:00
Dodji Seketeli
c2458fe1ae rhbz2114909 - Refer to changed base classes using their non-qualified names
This was filled at https://bugzilla.redhat.com/show_bug.cgi?id=2114909

When analysing the edit script representing the changes in the base
base classes of a given class, libabigail refers to the changed base
classes using their names.

The problem is that there can be several changed base classes that
have the same name, even though their /qualified/ names are
different.  That was wreaking having havoc down the road.

To solve the problem, use the qualified name of the base classes,
instead of their simple name.

Note that this change did also ameliorate other existing change
reports in the test suite.

While testing the fix, I realized that class_decl::base_spec doesn't
set its qualified name.  That leads to the fact that it's the
non-qualified name that is used for sorting the base class names in
the change reports.  This can lead to instabilities, depending on the
platform, in test output.  This is also fixed.

Fixed thus.

	* src/abg-comparison.cc
	(class_diff::ensure_lookup_tables_populated): Refer to the added
	or removed base class using its qualified name.
	* src/abg-ir.cc (class_decl::base_spec::base_spec): Set the
	qualified name of the base_spec.
	* tests/data/test-abidiff-exit/test-rhbz2114909-report-1.txt: New
	reference test output.
	* tests/data/test-abidiff-exit/test-rhbz2114909-v{0,1}.o: New
	input test binaries.
	* tests/data/test-abidiff-exit/test-rhbz2114909-v{0,1}.cc: Source
	code of the binaries, above.
	* tests/data/Makefile.am: Add the new test materials above to
	source distribution.
	* tests/test-abidiff-exit.cc (in_out_specs): Add the new tests to
	this harness.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64--libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64-report-0.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-10-20 17:17:09 +02:00
Dodji Seketeli
0d49c09e9c Bug 29650 - Caching class comparison result potentially too early
When structurally comparing two classes T and T' the overload of the
equals() function for abigail::ir::class_decl calls the overload of
equals() for abigail::ir::class_or_union to compare the data members
of the class.  If data members are equal, that later call caches the
result of comparing the data-members-only sub-object of T and T'.
That caching appears as if it's the result of comparing all of T and
T' that was cached, leading to misleading results down the road.

Result caching should not take place until the end of fulling
comparing T and T'.  Fixed thus.

	* src/abg-ir.cc (equal): In the overload of class_or_union do not
	cache the result comparing just the data members sub-types of of
	classes. In the overload for class_decl, put cycle detection
	management code /after/ the call to equals for class_or_union,
	because that called function does perform the cycle detection
	management as well; otherwise, that introduces an unwarranted
	redundancy.  In the overload of equals for union_decl, cache the
	result of the comparison.
	* tests/data/test-abidiff/test-PR18791-report0.txt: Adjust.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-10-10 12:34:52 +02:00
Dodji Seketeli
bdca22724e ir, writer: Go back to canonicalizing typedefs in the IR
Now that DIE and IR canonicalizing has progressed in precision,
especially due to fixing the canonical type propagation it seems like
we can go back to canonicalizing typedefs again.  This makes the
writer not needing to handle non-canonicalized types because only a
short number and types of types are still non-canonicalized.

Then I ran the test suite and hell broke lose.  Things would work on a
given platform but won't on others, etc.

So a great deal of the patch actually fixes issues uncovered by the
fact that we are back to canonicalizing typedefs.

The symptoms of many of the issues are related to emitting abixml in a
stable manner across toolchains.  But in reality those issues are
real, deeper ones.

This patch is thus ALSO an attempt at fixing all the issues at once
because they can't be separated.  Either the abixml is stable and
"make check" passes on all platforms, or it is not and testing fails
on some platforms.

I believe that at the core of the problems lies the observation that a
given typedef (of a given name) could appear several times (the number
of times not being quite constant) in a given class or namespace.
That would lead to some instabilities in the sorting and ordering of
type-ids depending on the toolchain being used, for instance.

To fix this add_or_update_class_type in the DWARF reader is taught to
avoid adding a typedef to a class if a member type of the same name
already exists at that class scope.  This handles the fact that a
given class can be built piece-wise in the DWARF.  Also, when handling
a typedef type, build_ir_node_from_die is taught to avoid creating a
typedef IR for a given scope (namespace, union or class) if said scope
already contains a type of the same name.  To be able to do that, the
handling of member types is moved from the ir::class_or_union type to
the ir::scope_decl type.  That way, all scopes (not just classes or
unions) can handle looking up for the (member) types they contain.

Another issue that was uncovered is that when emitting decl-only class
named A (in a namespace for instance) there can be some instability as
to which decl-only class A is emitted.  This is due to the fact that
libabigail considers all decl-only classes named A to be equal.  The
problem however is that a decl-only class A might have member types.
And a decl-only A declared in a translation unit somewhere might have
some member types that are different from the same decl-only A
declared in another translation unit.  This doesn't necessarily
violate the ODR, but rather, can be the result of compiler
optimization.  For instance, in a given translation unit, only a given
member type of the decl-only A is used by the code, whereas in another
one, another member type of the same decl-only A is used.  So only
partial views of A are emitted in the translation unit depending on
what is used.  Anyway, to handle that case, when comes the time to
emit the decl-only A in the ABIXML writer, write_class_decl now emits
all the member types of all the instances A known to the system.  This
hopefully removes the instability I was seeing.  To do that,
maybe_update_types_lookup_map<class_decl> has been taught to also keep
track of decl-only classes.  A new lookup_decl_only_class_types has
been defined to gather all the instances of a given decl-only class
known to the system.

Last but not least, the topological type sorting facilities carried by
the types {decl,type}_topo_comp has been fixed to ensure a more stable
sorting and also to ensure that "abilint foo.abi" emits the decls and
types in the same order as the one defined in foo.abi.  This fixes
another abixml instability I was seeing in the test suite across
different toolchains.  While doing that, I noticed that the ABIXML
reader was forgetting to properly mark the corpus as originating from
ABIXML.  So I fixed that too.

	* include/abg-fwd.h (lookup_decl_only_class_types): Declare new
	function.
	* src/abg-ir-priv.h (class_or_union::priv::member_types_): Move
	this data member into scope_decl::priv.
	(class_or_union::priv::priv): Do not take member types.
	* include/abg-ir.h (sort_type): Likewise.
	(namespaces_type): Add new typedefs.
	(scope_decl::insert_member_decl): Make this be non-virtual.
	(scope_decl::{insert_member_type, add_member_type,
	remove_member_type, get_member_types, get_sorted_member_types,
	find_member_type}): Move these methods here from ...
	(class_or_union::{insert_member_type, add_member_type,
	remove_member_type, get_member_types, get_sorted_member_types,
	find_member_type}): ... here.
	(class_or_union::insert_member_decl): Make this be non-virtual.
	(class_decl::insert_member_decl): Make this be non-virtual.
	(class_or_union::get_sorted_member_types): Declare ...
	* src/abg-dwarf-reader.cc (add_or_update_class_type): Do not add a
	member type to the class type being built if it already exists
	there.
	(build_ir_node_from_die): If a scope (namespace, union or class)
	already has a typedef, do not create a new one to add it there
	again.
	* src/abg-ir.cc (equals): In the overload for typedefs take into
	account the name of typedefs again.
	(lookup_decl_only_class_types): Define new function.
	(compare_using_locations): Define new static function that has
	been factorized out of ...
	(decl_topo_comp::operator()): ... here.  Also, two decls originate
	from an abixml corpus, compare them only using their artificial
	locations, meaning make them keep the same order as the order of
	the original abixml file.
	(type_top_comp::operator()): Likewise.
	(sort_types): Define new function.
	(scope_decl::priv::member_types_): Move this here from
	class_or_union::priv.
	(scope_decl::priv::sorted_member_types_): Define new data member.
	(scope_decl::{get_member_types, find_member_type,
	insert_member_type, add_member_type, remove_member_type}): Move
	these methods here from class_or_union.
	(scope_decl::get_sorted_member_types): Define new method.
	(is_non_canonicalized_type): Canonicalize typedefs.
	(lookup_type_in_map): Allow this to look through decl-only types
	to get their definition.  Otherwise, if only a decl-only was
	found, return it.
	(maybe_update_types_lookup_map<class_decl>): Allow adding
	decl-only class types to the map of classes held per TU and per
	corpus.
	(class_or_union::{class_or_union, add_member_decl,
	has_no_member}): Adjust.
	(class_or_union::{insert_member_type, add_member_type,
	add_member_type, remove_member_type, get_member_types,
	get_sorted_member_types, find_member_type}): Move these methods to
	scope_decl.
	({class_decl, class_or_union}::insert_member_decl): Remove the
	"before" parameter as it was not used anymore due to the re-use of
	the scope_decl::add_member that handles member types.
	* src/abg-reader.cc (read_corpus_group_from_input)
	(create_native_xml_read_context): Set the corpus origin.
	* src/abg-writer.cc (write_context::{m_nc_type_id_map,
	m_emitted_non_canonicalized_type_set,
	m_referenced_non_canonicalized_types_set}): Remove these maps that
	hold stuff for non-canonicalized types.
	(write_context::{type_has_existing_id, get_id_for_type,
	clear_type_id_map, has_non_emitted_referenced_types,
	record_type_as_referenced, type_is_referenced,
	record_type_as_emitted, type_is_emitted, clear_referenced_types,
	write_referenced_types, write_canonical_type_ids}): Adjust these
	as the maps for non-canonicalized types are gone.
	(write_context::{get_referenced_non_canonicalized_types,
	get_emitted_non_canonicalized_type_set}): Remove these methods.
	(write_decl_in_scope)
	(write_class_decl_opening_tag, write_union_decl_opening_tag)
	(write_union_decl): Adjust comments.
	(write_class_decl): Sort member types.  Also, When emitting a
	decl-only class, get all of the decl-only classes of the same name
	declared in several other TUs and emit all their member types into
	this decl-only class just once.  This reduces redundancies and
	sorting instabilities because for libabigail, all decl-only
	classes of a given name are equal, even if they have member types.
	* tests/data/test-abidiff/test-PR18791-report0.txt: Adjust.
	* tests/data/test-annotate/libtest23.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi:
	Likewise.
	* tests/data/test-annotate/test0.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test2.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/PR24690/PR24690-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR26261/PR26261-exe.abi: Likewise.
	* tests/data/test-read-dwarf/PR27700/test-PR27700.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-PR26568-1.o.abi: Likewise.
	* tests/data/test-read-dwarf/test-PR26568-2.o.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test0.abi: Likewise.
	* tests/data/test-read-dwarf/test0.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test1.hash.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/test2.so.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.
	* tests/data/test-read-write/test18.xml: Likewise.
	* tests/data/test-read-write/test28-without-std-fns-ref.xml:
	Likewise.
	* tests/data/test-read-write/test28-without-std-vars-ref.xml:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-09-20 11:43:34 +02:00
Dodji Seketeli
4bc513a8ae Fix IR comparison result caching and canonical type propagation tracking
Caching the result of IR comparison cannot happen on IR nodes that are
being compared in the context of type canonicalization if one of the
nodes is the target of canonical type propagation.  This is especially
true if the recursive IR node which comparison "temporarily" did yield
true (to avoid an infinite loop) at least until the comparison of the
rest of the sub-tree of the recursive type is done.  In that case, we
should not cache the result the comparison as it might change later.

The patch adds a way to track recursive types so that we know when not
to cache their comparison result.

As we now have a facility to track recursive types during canonical
type propagation (rather than just types that depend on recursive
types) we can be a bit more precise when confirming or cancelling
types that have been subject to canonical type propagation.

Also the patch cleans up the detection of comparison cycle to make it
more typesafe so that the macro
RETURN_TRUE_IF_COMPARISON_CYCLE_DETECTED can be used for class_decl
and union_decl, not just class_or_union.  It makes the code more
readable/maintainable is the equals overload for class_decl and
union_decl all have their proper call to
RETURN_TRUE_IF_COMPARISON_CYCLE_DETECTED.  The same is true for
mark_types_as_being_compared.

Doing that cleans up the detection of recursive types as well as the
types that depends on those recursive types.

	* src/abg-ir-priv.h (environment::priv::recursive_types_): Define
	new data member.
	(environment::priv::cache_type_comparison_result): Cache results
	only non-recursive and not dependant types, or when the result is
	"false".  In all these cases, the result, once cached, will not
	change.
	(environment::priv::mark_dependant_types_compared_until): Mark
	types as recursive at the same time others are marked as
	dependant.
	(environment::priv::{is_recursive_type, set_is_not_recursive}):
	Define new member functions.
	(environment::priv::{confirm_ct_propagation,
	cancel_ct_propagation}): Confirming canonical type propagation
	should happen for recursive types as well as their dependant
	types.
	* src/abg-ir.cc (return_comparison_result): Keep up with the
	book-keeping at all time when type canonicalization process is
	on-going.  Whenever we expect types that depends on recursive
	types, expect recursive types too, obviously.
	(type_base::get_canonical_type_for): Do not erase the comparison
	result cache between the canonicalization of two different types.
	(is_comparison_cycle_detected)
	(mark_types_as_being_compared, unmark_types_as_being_compared):
	Define new overloads for class_decl;
	(equals): In the overloads for class_decl and union_decl, use
	RETURN_COMPARISON_RESULT and mark_types_as_being_compared without
	casting it to class_or_union.
	* tests/data/test-abidiff/test-PR18791-report0.txt: Adjust.
	* tests/data/test-diff-dwarf/PR25058-liblttng-ctl-report-1.txt:
	Adjust.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Adjust.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-09-20 11:43:33 +02:00
Dodji Seketeli
dc88a6a576 dwarf-reader: Revamp the canonical type DIE propagation algorithm
During the type DIEs comparison for canonicalization we need to
perform the optimization called "canonical type propagation".  This is
very similar to what we do for type canonicalization at the IR level.
It's described in-extenso in abg-ir.cc, in the comment that starts
with "@defgroup OnTheFlyCanonicalization".

Basically during canonicalization, suppose we end-up comparing a
sub-type pair {Sl, Sr}.  Suppose Sr does already have a canonical
type.  Suppose also, that {Sl, Sr} ends up comparing equal.  We can
thus deduce that Sl would have the same canonical type as Sr.  So we
'propagate' the canonical type of Sr onto Sl.  Sl is said to have been
canonical-type-propagated from Sr.

Now, I need to introduce the concept of redundant type.

Consider an aggregate type T and its sub-types ST0, ST1 and ST2 which
looks like this:

	T
	+-- ST0
	|
	+-- ST1
	|    +
	|    |
	|    +-- T
	|
	+-- ST2

Notice how the sub-type ST1 itself has a sub-type T.

Now, consider the type T', similar to T, which looks like:

	T'
	+-- ST0'
	|
	+-- ST1'
	|    +
	|    |
	|    +-- T'
	|
	+-- ST2'
	|
	+-- ST'3

Now consider how libabigail compares those two types T and T'
member-wise, aka structurally:

		T                 T'
		+-- ST0           +-- ST0'
		|                 |
		+-- ST1           +-- ST1' <--- Let's call this point #0.
		|    +            |    +
		|    |            |    |
		|    +-- T        |    +-- T'  <--- Let's call this point #1.
		|                 |                 Note that the sub-types of
		+-- ST2           +-- ST2'          T and T' are not
		|                                   represented at this point
		+-- ST'3                            but they do exist!
						    Representing them would lead
						    to a never-ending graph, right?

The properties of T are compared against the properties of T', but to
complete that comparison, the sub-type ST0 is compared against ST0',
etc.  A comparison stack is thus maintained.  Each member of the stack
is the pair of sub-types being compared.  That content changes as
different sub-types are compared. Let's consider the content of the
stack when we reach the point #0 in the graph above. That stack
content would look like:

	[{T,T'} | {ST0, ST0'}]

If we keep going and reach the point #1, the content of the stack
becomes:

	[{T,T'} |{ST0, ST0'} | {T, T'}]

At this point, we see that {T,T'} appears twice in the stack. If we
keep going and explore again the sub-types of {T,T'}, an infinite loop
appears.  The pair {T,T'} is said to be redundant.

To avoid those infinite loops, redundancy detection is done by
compare_dies in abg-dwarf-reader.cc.  When compare_dies detects at #1 that
{T,T'} was already present in the stack then it returns "true" early,
as if in #1, T compares equal to T'.

But then what does that mean for the value of comparing {ST0,ST0'}?
The sub-type {T,T'} in #1 compared equal, so compare_dies assumes that
{ST0,ST0'} compares equal as well, right?  That is what libabigail
used to assume before the commit

	commit 7ecef63617
	Author: Dodji Seketeli <dodji@redhat.com>
	Date:   Mon Apr 4 15:35:48 2022 +0200

	    Canonicalize DIEs w/o assuming ODR & handle typedefs transparently

Well, it turns out we need to compare the entire tree of sub-types of
{T,T'} until we reach {ST2, ST2'}.  At that point, compare_dies sees
that ST2' has a sub-type ST3' where ST2 has none.  So {ST2,ST2'}
compares /different/.  So {T,T'} compares different.  So back to #0,
because {ST1,ST2'} has {T,T'} as sub-type (or said differently,
{ST1,ST2'} depends on the redundant pair {T,T'}) then {ST1,ST1'}
compares different.

So {ST1,ST1'} compares different even though it were initially thought to
compare equal because compare_dies had to get out early in #1,
considering that {T,T'} compared equal at that point.

Now, there are two ways to operate when we reach #1:

1/ Avoid performing canonical type propagation as soon as we detect
that {T,T'} is redundant.  That avoidance lasts until we finish
comparing {ST2,ST2'}, that is, until the complete comparison of
{T,T'}.  That means hat comparing every single sub-type is almost
assured to be done structurally, rather than canonically.

2/ Speculate that {T,T'} compare equal, unless proved otherwise.  If
{T,T'} proves to be equal, then things are well and fast.  If they
prove different, then {ST0,ST0'} must be edited afterwards to cancel
the canonical type propagation that might have taken place.  In other
words, sub-types that depends on redundant types pairs must be tracked
until the comparison of those redundant type pairs is done.  If a
redundant type pair compares different then all the sub-types that
depend on it must be walked to have their propagated canonical types
erase as if no canonical type propagation ever took place.

The first approach is the one I initially put in place with the patch
referred to above.  It proved to be super slow.  Analyzing the kernel
was taking literally hours.  Oops.

This patch implements the second approach.  It's more involved than
the first approach.  But it brings the time down to around 2 minutes
on a reasonably fast machine.  This is still slower than what I would
like to see, but it's way better than what had with the first
approach.

A subsequent patch will bring the analysis time for the kernel further
down.  But in the mean time, this one is really needed, I think.

So the patch introduces a new type named offset_pairs_stack_type to
track the pairs of type DIEs being compared.  Each DIE is now
identified by a new offset_type type.  That type  contains the
traditional DIE offset using the Dwarf_Off type from elfutils, but it
also contains the source of that DIE.  The offset_pairs_stack_type
also tracks redundant type pairs and their dependant type pairs.

compare_dies is modified to return a value that is an instance of the
new enum comparison_result.  The results can be
COMPARISON_RESULT_EQUAL when a type pair compares equal,
COMPARISON_RESULT_DIFFERENT when a type pair compares different,
COMPARISON_RESULT_CYCLE_DETECTED when a redundant type is detected,
leading to a comparison cycle, and COMPARISON_RESULT_UNKNOWN when the
outcome of the comparison cannot be known because we are comparing a
pair that depends on a redundant pair.

A new function return_comparison_result is introduced.  It's intended
to be invoked right before returning from compare_dies.  It looks at
the actual comparison result and depending on the state of the stack
of type pairs being compared, handles the book keeping of redundant
types and their dependant types.  It also handles when to propagate
canonical types if necessary and when to cancel the canonical types
that might have been propagated.

The ABG_RETURN macro has been adapted to invoke
return_comparison_result before returning out from compare_dies.

	* src/abg-ir-priv.h (enum comparison_result): Define new enum.
	* src/abg-dwarf-reader.cc (type_comparison_result_to_be_cached)
	(maybe_cache_type_comparison_result)
	(get_cached_type_comparison_result)
	(maybe_get_cached_type_comparison_result)
	(maybe_propagate_canonical_type, propagate_canonical_type)
	(return_comparison_result): Define new static functions.
	(has_offset_pair, insert_offset_pair, erase_offset_pair)
	(have_offset_pair_in_common): Remove static functions.
	(read_context::die_comparison_visits_): Remove data member.  The
	concept supported by this data member is now replaced by caching
	the results of comparing aggregate types, especially those that
	are not yet canonicalized.  This essentially prevents the same
	aggregate type pair to be compared again and again.
	(read_context::{die_comparison_results_, compare_count_,
	canonical_propagated_count_, cancelled_propagation_count_}): New
	data members.
	(read_context::initialize): Initialize the new data members
	compare_count_, canonical_propagated_count_,
	cancelled_propagation_count_ of integral type.
	(read_context::{erase_canonical_die_offset}): New member
	functions.
	(struct offset_pairs_stack_type): Define new type.
	(die_offset): Remove.
	(is_canon_type_to_be_propagated_tag): Add union types to the set
	of types for which canonical type propagation might occur.
	(is_type_die_to_be_canonicalized): Add function types and array
	types to the types to be canonicalized.
	(ABG_RETURN): Change this macro to consider
	COMPARISON_RESULT_DIFFERENT rather  than the "false" boolean.
	Also, it uses the new return_comparison_result function.
	(ABG_RETURN_FALSE): Likewise, use the new return_comparison_result
	function.
	(SET_RESULT_TO_FALSE): Make this return
	COMPARISON_RESULT_DIFFERENT.
	(SET_RESULT_TO, RETURN_IF_COMPARISON_CYCLE_DETECTED): Define new
	macros.
	(compare_dies): Make this return comparison_result rather than
	just a bool.  This is also the core of the overhaul of the
	canonical DIE propagation algorithm.  The algorithm is now similar
	to the one implemented in the equals function for class_or_union
	types in abg-ir.cc.  It's described in the comment that starts
	with '@defgroup OnTheFlyCanonicalization' in abg-ir.cc.  The type
	of the aggregates_being_compared parameter is now
	offset_pairs_stack_type in parameter.  No more need for the
	redundant_aggregates_being_compared parameter.  The new
	offset_type that also encapsulates the source of the offset is now
	used in lieu of the Dwarf_Off type.  Results of comparing
	aggregates being compared are now cached.  When comparing
	aggregates, use the RETURN_IF_COMPARISON_CYCLE_DETECTED to return
	early if a cycle is detected.  The invocation of the ABG_RETURN
	macro (especially the call to return_comparison_result) is where
	the book keeping for canonical types propagation takes place, so
	remove the explicit code that was handling that from the end of
	this function.
	(read_debug_info_into_corpus): Print statistics about the number
	of aggregates compared and canonical-type-propagated.
	* tests/data/test-annotate/test14-pr18893.so.abi: Adjust.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64--2.24.2-30.fc30.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.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/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.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-09-20 11:43:32 +02:00
Dodji Seketeli
c49d650827 dwarf-reader: Simplify the canonicalization decision of types added to IR
This is a long overdue clean-up.

Back in the day when we had no DWARF type DIE canonicalization, there
could be a LOT of IR types to be canonicalized.  To store set of those
types to be canonicalized, we the used the already existing
association type DIE offset -> IR types that we had, and so we only
had to store the DIE offsets of the IR types that we wanted to
canonicalize.  At canonicalization time, we'd walk the set of DIE
offsets we stored on the side, use the association type DIE offset ->
IR types to retrieve the IR type to canonicalize and we'd canonicalize
it.  This is somewhat complicated.

Now that we have DWARF DIEs canonicalization, the number of IR types
dropped significantly so this complicated scheme is no more warranted.

So this patch drops that indirection and stores the IR types to be
canonicalize into a vector of IR types and that's it.  Yay, less code.

	* src/abg-dwarf-reader.cc (maybe_canonicalize_type): Remove
	the overload that takes a Dwarf_Die* parameter.
	(operator++(die_source& source)): Likewise.
	(read_context::{types_to_canonicalize_,
	alt_types_to_canonicalize_,
	type_unit_types_to_canonicalize_}): Remove these data members
	of type vector<Dwarf_Off>.  (read_context::initialize): Remove
	invocations to alt_types_to_canonicalize_.clear(),
	type_unit_types_to_canonicalize_.clear(), and
	extra_types_to_canonicalize_.clear().
	(read_context::extra_types_to_canonicalize_): Rename this into
	read_context::types_to_canonicalize_, of type
	vector<type_base_sptr>.
	(read_context::types_to_canonicalize): Remove these member
	functions that take a parameter of type die_source.
	(read_context::extra_types_to_canonicalize): Rename this
	function into types_to_canonicalize.  It returns a type const
	vector<type_base_sptr>&.
	(read_context::schedule_type_for_late_canonicalization):
	Remove this overload that takes a type const Dwarf_Die*.  In
	the overload that takes a parameter const type_base_sptr
	however, rename the invocation to
	extra_types_to_canonicalize_.push_back(t) into
	types_to_canonicalize_.push_back(t).
	(read_context::canonicalize_types_scheduled): This doesn't
	take a die_source parameter anymore.  It now only cycles
	through the types retrieved by types_to_canonicalize() to
	canonicalize them.
	(read_context::add_late_canonicalized_types_stats): Remove the
	die_source parameter.  Use types_to_canonicalize().
	(read_context::perform_late_type_canonicalizing): Just call
	read_context::canonicalize_types_scheduled().
	(build_ir_node_from_die): Adjust calls to maybe_canonicalize_type.
	Also, really canonicalize the function type when a function decl is
	constructed.
	* tests/data/test-annotate/test13-pr18894.so.abi: Adjust.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.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/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.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.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-09-05 18:22:46 +02:00
Dodji Seketeli
f001c14eee tests-diff-{filter,pkg,pkg-ctf}: Fix tests broken by the previous commit
* tests/data/test-diff-filter/test41-report-0.txt: Adjust.
	* tests/data/test-diff-pkg-ctf/gmp-6.x.x86_64-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-07-18 23:50:34 +02:00
Dodji Seketeli
5b3516a5e7 dwarf-reader: Support DWARF incomplete class types
The problem this patch addresses is visible when doing:

$ fedabidiff --debug --self-compare -a --from fc36 wildmagic5

More specifically:

tools/abidw --noout -d usr/lib/debug/ usr/lib64/libWm5Mathematics.so.5.17

This is reported at
https://sourceware.org/bugzilla/show_bug.cgi?id=29302#c2:

  Functions changes summary: 0 Removed, 9 Changed, 0 Added functions
  Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

  9 functions with some indirect sub-type change:

    [C] 'method virtual Wm5::ConvexHull<double>::~ConvexHull(int)' at
    Wm5ConvexHull.h:24:1 has some indirect sub-type changes:
      implicit parameter 0 of type 'Wm5::ConvexHull<double>*' has
    sub-type changes:
        in pointed to type 'class Wm5::ConvexHull<double>':
          type size changed from 384 to 0 (in bits)
          1 member function deletion:
            'method virtual Wm5::ConvexHull<double>::~ConvexHull(int)'
    at Wm5ConvexHull.cpp:32:1
          no member function changes (2 filtered);

    [C] 'method virtual Wm5::ConvexHull<float>::~ConvexHull(int)' at
    Wm5ConvexHull.h:24:1 has some indirect sub-type changes:
      implicit parameter 0 of type 'Wm5::ConvexHull<float>*' has
    sub-type changes:
        in pointed to type 'class Wm5::ConvexHull<float>':
          type size changed from 320 to 0 (in bits)
          1 member function deletion:
            'method virtual Wm5::ConvexHull<float>::~ConvexHull(int)'
    at Wm5ConvexHull.cpp:32:1
          no member function changes (2 filtered);

[...]

It appears that some class type DIEs don't have any size information
and are marked as being declarations.  These have an incomplete set of
data member / virtual member functions compared to DIEs for the SAME
types described elsewhere in the DWARF.

About these, the specification says:

    5.7.1 Structure, Union and Class Type Entries
    [...]

    An incomplete structure, union or class type is represented by a
    structure, union
    or class entry that does not have a byte size attribute and that has a
    DW_AT_declaration attribute.

But then the DWARF reader doesn't know about these so it creates
several types from these incomplete DIEs.  Those types are thus
incorrect.  And that leads to spurious self comparison changes down
the road.

This patch thus detects that the DIEs is for an incomplete type and
does not build an IR for its sub-types.  It rather builds a
declaration-only type.

Then later, that declaration-only type is resolved to its
corresponding definition using the existing
read_context::resolve_declaration_only_classes function.

The patch also removes the temporary speed hack that was introduced
into read_context::resolve_declaration_only_classes() by the commit:

    b9af1f35 dwarf-reader: Avoid long comparisons when resolving C++ decl-only classes

This is no longer a problem thanks to the great speed improvement we
have from the commit:

    69795d1b Bug 29303 - Cache the result of structural aggregate comparison

	* src/abg-dwarf-reader.cc
	(read_context::resolve_declaration_only_classes): Do not avoid
	comparing ODR-relevant classes.
	(add_or_update_class_type): Detect incomplete classes and treat
	them as decl-only types.  They'll be resolved to their proper
	complete types later, by
	read_context::resolve_declaration_only_classes.
	* tests/data/test-annotate/libtest23.so.abi: Adjust.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.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/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/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-07-18 15:43:22 +02:00
Dodji Seketeli
2b8b8bc5a8 Better Handle naming typedefs on anonymous enums
While debugging a self comparison error, I realized that some types
where comparing different during IR type canonicalization for no good
reason.  Looking deeper, I realized it's due to an anonymous enum
comparing different to the same anonymous enum defined elsewhere.
Both anonymous enums have naming typedefs.  The discrepancy is due to
the fact that one of these enums didn't have its naming typedef
applied, by the DWARF reader. This is because the DWARF reader
"re-uses" typedef types whenever it can, and thus re-uses naming
typedefs too.  Thinking deeply about this, I think naming typedefs
should not be re-used, otherwise, some anonymous types would lack
their naming typedefs.  Oops.

So the patch avoids typedefs to be re-used altogether.  There doesn't
seem to be any performance hit.

With that fixed, another problem came up: Some typedefs of type foo
are compared to said type foo and the comparison yields "false",
wrongly.  This is in the context of a type 'foo' used by type 'bar'
defined in a translation unit, and the same type 'bar' uses a typedef
of 'foo' in another translation unit.  Both types 'bar' should compare
equal, but don't, today.  This is true especially for function types.
The patch strips typedefs off of the types of function parameters when
comparing function types.  To make things consistent, typedefs are
stripped off of function parameters when function types (and decls)
are pretty printed for internal purposes, especially for type
canonicalization.

	* src/abg-dwarf-reader.cc (build_typedef_type): Do not re-use
	typedefs.
	* src/abg-ir.cc	(get_function_type_name, get_method_type_name)
	(function_decl::get_pretty_representation_of_declarator): Strip
	typedefs when the function name is computed for internal purposes.
	(equals):  In the overload for function_decl::parameter, strip
	typedefs when comparing parameter types.
	* tests/data/test-annotate/libtest23.so.abi: Adjust.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-diff-dwarf/test2-report.txt: Likewise.
	* tests/data/test-diff-filter/test3-report.txt: Likewise.
	* tests/data/test-diff-pkg/PR24690/PR24690-report-0.txt: Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* 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/test14-pr18893.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Likewise.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-07-14 16:15:23 +02:00
Dodji Seketeli
7ecef63617 Canonicalize DIEs w/o assuming ODR & handle typedefs transparently
When canonicalizing DIEs, if two type DIEs have the same textual
representation and we are looking at a C++ DIE, then we assume the two
DIEs are equivalent because of the "One Definition Rule" of C++.

There are binaries however where there seem to be type DIEs that are
slightly different and yet with the same textual representation.  It
seems that this leads to some heisenbugs depending on which of the two
DIEs is "kept".  That order would then depend on whatever the linker's
output is at a particular moment when linking the binary.  Those
slight differences (i.e, modulo typedefs, for instance) are a pain to
reproduce across binaries that are re-linked.  So I am removing this
optimization.  As it doesn't seem to be so useful anymore, given all
the areas of the pipeline that go improved recently, speed-wise.

After doing that, it appeared the comparison engine was seeing more
DIE kinds.  So rather than aborting when seeing an unexpected DIE
kind, we now assume the two DIEs we are seeing are different.  They
are thus not canonicalized.  That's not a problem because the IR level
type canonicalizer will pick that up and fully canonicalize the type
at that level.

So as that is in place, it appeared we were doing canonical DIE
propagation even in cases where we should not.  Namely, when a subset
of the stack of aggregates being compared depends on a recursive (or
redundant) sub-type, no canonical type DIE propagation should be
performed.  The patch thus detects that state of things and disables
the canonical type DIE propagation in that case.

Once this change in place, as the DIE canonicalizer started to look
into more types, the IR started to get more types that were deemed
equal to their decl-only counterpart before, and so were represented
those decl-only counterpart by virtue of the ODR.

That uncovered the long standing issue described below.

Canonicalizing typedefs is done today by considering that two typedefs
that have different names are different even if they have the same
underlying types.

That means we can have two types T and T' (in a binary) that are
equivalent modulo a sub-type that is a typedef with different names in
T and T', yet with equivalent underlying types.  Today, libabigail
would consider T and T' different, even though they are equivalent
from an ABI standpoint.

This can lead to spurious changes that we have to handle later by
adding passes that would suppress those spurious changes.

This patch thus changes the structural comparison for typedefs by not
taking the typedef name into account anymore.  Also, typedefs don't
carry canonical types anymore.  That way, to compare typedefs,
libabigail always look into their underlying types.

To adapt the precision of the abixml output, the patch now uses a
special set (to track emitted non-canonicalized types) and a special
map (to track type ID for non-canonicalized types) as those can't be
put in the classical maps that track types using their canonical
types.

	* include/abg-fwd.h (peel_typedef_pointer_or_reference_type):
	Declare new function.
	* src/abg-dwarf-reader.cc (read_context::{compute_canonical_die,
	get_canonical_die, get_or_compute_canonical_die}): Don't
	special-case ODR-relevant cases.
	(is_canon_type_to_be_propagated_tag): Rename
	is_canonicalizeable_type_tag into this.
	(erase_offset_pair): Make this return a bool, not void.
	(have_offset_pair_in_common, try_canonical_die_comparison)
	(notify_die_comparison_failed): Define new static functions.
	(ABG_RETURN, ABG_RETURN_FALSE): Define new macros.
	(compare_dies): Handle DW_TAG_{class,unspecified}_type DIES.  Also
	if a comparing a DIE kind is not supported, assume the comparison
	yields "false" for the purpose of canonicalization.  Add a new
	parameter for redundant aggregates being compared.  Use the
	redundant aggregate set to detect if a redundant aggregate has
	been detected and is still being "explored"; if that's the case,
	then canonical DIE propagation is de-activated.  This might incur
	a performance hit.  Use the new ABG_RETURN and ABG_RETURN_FALSE
	macros.  Use the new try_canonical_die_comparison to compare
	canonical DIEs rather than doing it by hand.
	(build_typedef_type): Don't try to rely on canonical typedefs
	DIEs.
	* src/abg-ir.cc
	(type_topo_comp::has_artificial_or_natural_location): Define new
	method.
	(type_topo_comp::operator(const type_base*, const type_base*)): In
	this topological comparison operator of types, when two types have
	the same textual representation, if they don't have any location,
	if they are pointer/reference/typedef types, use the textual
	representation of their ultimate underlying type for sorting
	order.
	(peel_typedef_pointer_or_reference_type): Define new function.
	(compare_types_during_canonicalization): Perform the structural
	canonical comparison first.
	(equals): In the overload for array_type_def::subrange_type&,
	remove unused code. In the overload for typedef_decl& don't
	compare typedef names.  In the overload for class_or_union, make
	the RETURN macro *NOT* propagate canonical type because this equal
	function is used as a subroutine by overloads for class and union.
	That means that the class_or_union equal function can return true,
	and still, the caller (overload for class_decl or union_decl) can
	later return false; in that case, we don't want canonical type to
	be propagated.  In the overload for class_decl::base_spec, use the
	ABG_RETURN macro when returning comparing decl-bases.  In the
	overload for class_decl, use ABG_RETURN when returning the result
	of comparing class_or_union artifacts.
	(maybe_propagate_canonical_type):  If we are using canonical type
	comparison, then do not propagate the type, if
	WITH_DEBUG_TYPE_CANONICALIZATION is defined.
	(is_non_canonicalized_type): Add typedefs to the set of
	non-canonicalized types.
	* src/abg-writer.cc (struct non_canonicalized_type_hash, struct
	non_canonicalized_type_equal): Define new functors.
	(typedef nc_type_ptr_set_type): Define a new non-canonicalized set
	type.
	(typedef nc_type_ptr_istr_map_type): Define a new map of
	non-canonicalized types/interned string map.
	(write_context::{m_nc_type_id_map,
	m_emitted_non_canonicalized_type_set,
	m_referenced_non_canonicalized_types_set}): New data members.
	(write_context::type_has_existing_id): Look for non-canonicalized
	types in the m_nc_type_id_map map.
	(write_context::get_id_for_type): Use m_nc_type_id_map for
	non-canonicalized types.
	(write_context::clear_type_id_map): Clear m_nc_type_id_map too.
	(write_context::get_referenced_non_canonicalized_types): Renamed
	write_context::get_referenced_non_canonical_types into this.  Make
	it return the new
	write_context::m_referenced_non_canonicalized_types_set.
	(write_context::has_non_emitted_referenced_types): Just use
	write_context::type_is_emitted as it knows where to look up for
	non-canonicalized types.
	(write_context::record_type_as_referenced): Use
	m_referenced_non_canonicalized_types_set to store referenced
	non-canonicalized types.  The other types are stored in
	m_emitted_set as previously.
	(write_context::type_is_emitted): Look into
	m_emitted_non_canonicalized_type_set for non-canonicalized types.
	Other types are still in m_emitted_type_set.
	(write_context::{record_decl_only_type_as_emitted,
	decl_only_type_is_emitted, get_emitted_decl_only_types_set}):
	Remove methods.
	(write_context::get_emitted_non_canonicalized_type_set): Define
	new method.
	(write_context::clear_referenced_types): Clear
	m_referenced_non_canonicalized_types_set too, as
	m_referenced_non_canonical_types_set is no more.
	(write_context::referenced_type_should_be_emitted): Use only
	write_context::type_is_emitted as it knows how to check it all
	now.
	(write_referenced_types): Use the more compact ranged-base for
	loops.
	(write_translation_unit): Write the non-canonicalized types that
	are not yet emitted.
	(write_class_decl, write_union_decl): Adjust recording type as
	emitted.
	(write_canonical_type_ids): Adjust.
	* tests/data/test-abidiff/test-PR18791-report0.txt: Adjust.
	* tests/data/test-annotate/libtest23.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi: Likewise.
	* tests/data/test-annotate/test0.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Adjust.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-annotate/test2.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-annotate/test3.so.abi: Likewise.
	* tests/data/test-annotate/test5.o.abi: Likewise.
	* tests/data/test-diff-dwarf-abixml/PR25409-librte_bus_dpaa.so.20.0.abi:
	Likewise.
	* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi:
	Likewise.
	* tests/data/test-diff-dwarf/PR25058-liblttng-ctl-report-1.txt: Likewise.
	* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm--libICE-1.0.9-2.el7.x86_64:
	Likewise.
	* tests/data/test-diff-pkg/nmap-7.70-5.el8_testjcc.x86_64-self-check-report-0.txt:
	Likewise
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test39-opaque-type-report-0.txt:
	Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-A.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-conflicting-type-syms-a.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-conflicting-type-syms-b.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-functions-declaration.abi:
	Likewise.
	* tests/data/test-read-ctf/test1.so.abi: Likewise.
	* tests/data/test-read-ctf/test1.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test2.so.abi: Likewise.
	* tests/data/test-read-ctf/test2.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test5.o.abi: Likewise.
	* tests/data/test-read-ctf/test7.o.abi: Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR24378-fn-is-not-scope.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR26261/PR26261-exe.abi: Likewise.
	* tests/data/test-read-dwarf/PR27700/test-PR27700.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-PR26568-1.o.abi: Likewise.
	* tests/data/test-read-dwarf/test-PR26568-2.o.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-suppressed-alias.o.abi:
	Likewise.
	* tests/data/test-read-dwarf/test0.abi: Likewise.
	* tests/data/test-read-dwarf/test0.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test1.hash.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/test2.so.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.hash.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/test3-alias-1.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-2.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-3.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-4.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3.so.abi: Likewise.
	* tests/data/test-read-dwarf/test3.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test5.o.abi: Likewise.
	* tests/data/test-read-dwarf/test5.o.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.
	* tests/data/test-read-write/test18.xml: Likewise.
	* tests/data/test-read-write/test28-without-std-fns-ref.xml:
	Likewise.
	* tests/data/test-read-write/test28-without-std-vars-ref.xml:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-06-20 17:26:58 +02:00
Dodji Seketeli
9eb931c10d comparison: Avoid sorting diff nodes with wrong criteria
This should address PR28939, reported at
https://sourceware.org/bugzilla/show_bug.cgi?id=28939

In function_type_diff::chain_into_hierarchy, the diff details
represented by the diff nodes of the function parameters are already
sorted in the vector priv->sorted_changed_parms_by_id_.  Note that the
sorting of function parameter diff nodes was done using a criterion
that takes into account the position of each function parameter.

Members of the vector priv->sorted_changed_parms_by_id_ are then added
to the diff graph using diff::append_child_node.

The problem is that diff::append_child_node sorts the children nodes
/again/, this time using a criterion that is different from the one
used in function_type_diff::chain_into_hierarchy.  This is wrong.

This patch prevents diff::append_child_node from sorting the children
node because they have been sorted already.

	* src/abg-comparison.cc (diff::append_child_node): Do not sort
	children nodes here because they must have been sorted already.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt: Adjust.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt: Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt: Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* 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:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-03-10 10:57:53 +01:00
Dodji Seketeli
861e4670b6 Bug 28450 - Fix cloned member function handling in DWARF
When the DWARF reader encounters a function DIE 'f' that has a
DW_AT_specification that points to a member function, the current
implementation creates a function IR for the member function.  The
problem is that the member function has no ELF symbol associated to
it.  The ELF symbol is associated to 'f', not to the member function.
The DWARF reader then wrongly drops the member function on the floor
because it has no ELF symbol function associated.  So that member
function specification never gets its concrete function represented in
the IR.

This patch fixes the issue by detecting that the member function is
the "specification" for 'f' and that the ELF symbol associated to it
might not be there.  In that case, if the ELF symbol is on the 'f' DIE
itself, we get it from there.

The patch makes more member functions to be represented so it uncovers
a latent issue which is explained below.

Today, some compilers can emit redundant DWARF constructs like "const
reference" or "const void".  A reference is always const so the const
is superfluous.  A similar thing can be said about "const void".
maybe_strip_qualification detects those constructs and rewrites the IR
into a "no-op qualified reference", or a "no-op qualified void".  The
no-op was needed in the previous incarnations of the DWARF reader
because it was expecting a 'qualified type' IR to be associated to a
qualified type DIE.  Note, however, that that expectation has been
generally relaxed since then.

The problem is that the comparison engine, when building the diff IR
needs to strip those no-op qualified types off, to avoid having
spurious change diagnostics.  That stripping introduces some
challenges because the tree is more or less un-mutable at that point
(after type canonicalization) so the stripping can only be partial.

This patch removes the no-op qualified types altogether, rather than
trying harder to handle them down the line.  In other words,  a const
reference is now represented as a reference and a const void as a
void.  This makes things much simpler.

The problem however is that the in-memory IR (and thus the emitted
ABIXML) doesn't have any no-op qualified type anymore.  So comparing
an old ABIXML that contains those no-op qualified types against its
origin ELF corpus can yield some spurious diagnostics.  To fix it, one
needs to re-generate the ABIXML file.

This patch bumps the ABIXML version to 2.1 and introduces a new
ABIXML-FORMAT-VERSIONS file that documents the format changes.

	* ABIXML-FORMAT-VERSIONS: New file that documents the version
	changes of the ABIXML-FORMAT-VERSIONS.
	* include/abg-fwd.h (look_through_no_op_qualified_type): Remove
	this function declaration.
	(strip_useless_const_qualification): Declare new function
	declaration.
	* src/abg-comparison.cc (compute_diff_for_types): Avoid stripping
	off no-op-qualified types as these beasts don't exist anymore.
	(redundancy_marking_visitor::visit_end): Allow a variable which
	type has local changes to be considered redundant if its type is
	itself redundant.
	* src/abg-config.cc (config::config): Bump the abixml version from
	2.0 to 2.1.
	* src/abg-dwarf-reader.cc (maybe_strip_qualification): Factorize
	out the new strip_useless_const_qualification function from here.
	(build_or_get_fn_decl_if_not_suppressed): If the function is
	created but doesn't have an ELF symbol associated to it, then
	update it so that the ELF symbol can be associated.  Otherwise,
	potential_member_fn_should_be_dropped might later drop that
	function on the floor because it doesn't have any ELF symbol
	associated.
	* src/abg-ir.cc (strip_useless_const_qualification): Define this,
	which is has been factorized out of maybe_strip_qualification.
	(look_through_no_op_qualified_type): Remove this definition.
	(equals): In the overload for reference_type_def, do not peel
	typedefs off from the reference before comparison.  This is now
	useless as the comparison infrastructure got a lot better.  In the
	overload for references, stop using
	look_through_no_op_qualified_type as this function doesn't exist
	anymore.
	* src/abg-tools-utils.cc (abidiff_status_has_error): Detect when
	there is a usage error as well.
	* tests/data/test-types-stability/PR28450-libepetra.so.13.0: Add
	new testing binary to the repository.
	* tests/data/Makefile.am: Add the new testing binary above to
	source distribution.
	* tests/test-types-stability.cc (elf_paths): Add the new test to
	this test harness.
	* tests/test-diff-dwarf-abixml.cc (main): Add better error messages.
	* tests/data/test-abidiff-exit/test-member-size-report0.txt: Adjust.
	* tests/data/test-annotate/libtest23.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi: Likewise.
	* tests/data/test-annotate/test0.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test6.so.abi: Likewise.
	* tests/data/test-annotate/test7.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi: Likewise.
	* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi: Likewise.
	* tests/data/test-diff-dwarf/test0-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test28-vtable-changes-report-0.txt: Likewise.
	* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt: Likewise.
	* tests/data/test-diff-filter/test0-report.txt: Likewise.
	* tests/data/test-diff-filter/test01-report.txt: Likewise.
	* tests/data/test-diff-filter/test10-report.txt: 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/test30-pr18904-rvalueref-report2.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test9-report.txt: Likewise.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64--libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-10.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-12.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-14.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-16.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-4.txt: Likewise.
	* tests/data/test-diff-suppr/test31-report-1.txt: Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test0.abi: Likewise.
	* tests/data/test-read-dwarf/test0.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test1.hash.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/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/test2.so.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.hash.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/test3-alias-1.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-2.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-3.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3-alias-4.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test3.so.abi: Likewise.
	* tests/data/test-read-dwarf/test3.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test4.so.abi: Likewise.
	* tests/data/test-read-dwarf/test4.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test5.o.abi: Likewise.
	* tests/data/test-read-dwarf/test5.o.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test6.so.abi: Likewise.
	* tests/data/test-read-dwarf/test6.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test7.so.abi: Likewise.
	* tests/data/test-read-dwarf/test7.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.abi: Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.
	* tests/data/test-read-write/test-crc.xml: Likewise.
	* tests/data/test-read-write/test26.xml: Likewise.
	* tests/data/test-read-write/test27.xml: Likewise.
	* tests/data/test-read-write/test28-without-std-fns-ref.xml: Likewise.
	* tests/data/test-read-write/test28-without-std-vars-ref.xml: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-11-12 18:31:28 +01:00
Dodji Seketeli
824e104a23 Add debug info package for wireshark-cli-3.4.9-1.fc36.x86_64.rpm
I forgot to add the wireshark-cli-3.4.9-1.fc36.x86_64.rpm debug info
package for the test entry that uses it in tests/test-diff-pkg.cc.
It's not necessary on the x86-64 platform, but on many others, it
seems the alternate debug info contained in that package is needed.
So I am adding it in here.

	* tests/data/test-diff-pkg/wireshark/wireshark-debuginfo-3.4.9-1.fc36.x86_64.rpm:
	Add new debug info package.
	* tests/data/Makefile.am: Add it to the source distribution.
	* tests/test-diff-pkg.cc: Use the new debug info package in the
	test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-10-18 12:53:40 +02:00
Dodji Seketeli
991283269e Bug 28364 - libwiretap fails self comparison
In this case, thanks to all the debugging infrastructure in place,
especially the canonical type debugging infrastructure, I was able to
notice that there was a canonicalization error on a function type when
reading the libwiretap binary as in:

    $ build/tools/abidw --debug-tc /usr/lib64/libwiretap.so.11.0.8
    structural & canonical equality different for type: function type void (wtap*)
    in compare_types_during_canonicalization at: /home/dodji/git/libabigail/PR28364/src/abg-ir.cc:13575: execution should not have reached this point!
    Abandon (core dumped)
    $

When digging deeper, I noticed that, in the DWARF reader, when
building a function type, we are associating a "textual
representation" of the function type 'void (wtap*)' to its DIE (inside
the current translation) way too early.

By too early, I mean, the association was done before the function
type was fully 'built'.  Its parameters were not 'collected', for
instance.  So that means that a 'pointer to that function type' could
be formed, with a wrong representation, during the time where the
function type wasn't fully formed.  Just moving the association to
after the type was fully constructed solved the issue.

This one was hard to spot!

Later, this uncovered the fact that we could now have (and thus
serialize) member functions of unions.  And it turned out the abixml
reader didn't expect those.  Oops.  I fixed that one as well.

	* src/abg-dwarf-reader.cc (build_function_type): Associate the DIE
	representation to the constructed type once it's fully built.
	* src/abg-reader.cc (build_function_type): Support member function of unions.
	* tests/data/Makefile.am: Add the new test input files to the
	source distribution.
	* tests/data/test-diff-pkg/wireshark/wireshark-cli-3.4.9-1.fc36.x86_64-self-check-report.txt:
	Add new test input file.
	* tests/data/test-diff-pkg/wireshark/wireshark-cli-3.4.9-1.fc36.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/wireshark/wireshark-cli-debuginfo-3.4.9-1.fc36.x86_64.rpm:
	Likewise.
	* tests/test-diff-pkg.cc (in_out_specs): Add these new test input
	files to this test harness.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-10-18 09:56:53 +02:00
Dodji Seketeli
86a1738d96 Bug 27970 - Duplicated member functions cause spurious self comparison changes
Sometimes, in DWARF, a given class can even be defined piece-wise
across several DIEs.  The first DIE would defined some properties and
subsequent DIEs would define others.  dwarf-reader already supports
this for most properties.  Some properties however can be duplicated
across two DIES.

For instance, a DIE describing a class 'C' can define a virtual member
function, and then a subsequent different DIE further describing other
properties of the same class C would define the same virtual member
function again.  In that case, we should not define the virtual member
function twice in the IR of C that is being built.

Libabigail is failing to do exactly that.  It's representing the
virtual member function of C twice in this case.

	* src/abg-dwarf-reader.cc (fixup_functions_with_no_symbols): When
	the function decl is finally associated to its (publicly defined)
	ELF symbol, mark it as being exported.
	(finish_member_function_reading): Don't risk marking a virtual
	function as being non-virtual when updating its properties.
	(build_or_get_fn_decl_if_not_suppressed): Update comment.  If the
	member function is already present in the class, do not create a
	new one; rather, reuse the existing one.  It's going to be later
	updated by finish_member_function_reading.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Adjust.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.

	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi: Likewise.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.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>
2021-09-22 17:19:10 +02:00
Dodji Seketeli
1115e3f08e abipkgdiff: Do not erase working dirs before we are done using them
* tools/abipkgdiff.cc (compare_prepared_userspace_packages):
	Removing working directories "early" prevents e.g,
	dwarf_reader::get_soname_of_elf_file from accessing those files.
	So do not remove them until the very end.
	* tests/data/test-diff-pkg/libxcrypt-4.1.1-6.el8.x86_64--libxcrypt-4.1.1-6.el8.x86_64-output-1.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-09-21 16:48:22 +02:00
Dodji Seketeli
321da66678 Bug 28316 - Failure to represent typedef named anonymous enums
Consider these two anonymous enum declarations in these different contexts:

enum {A0 = 0; A1 = 1;} global0; // 1/: anonymous enum

typedef enum {E0 = 0; E1 = 1;} E; // 2/: anonymous enum named by a typedef.
E global0;

In the first context "1/", the type of the global variable is an
anonymous enum that is used as such.

In the second context "2/", the type of the global variable is an
anonymous type that is named by the typedef 'E'.  So then, it's E that
is used to designate the enum.  The anonymous type is thus never used
directly.  In essence, it's the same thing as if it was declared as
enum E {E0 = 0; E1 = 1;};

Right now, libabigail canonicalizes the enum 1/ and 2/ together and
that results in 1/ being canonically equal to 2/.

So, when saving the corpus into abixml, because enum 1/ and enum 2/ can be
used interchangeably, either 1/ or 2/ is going to be saved.  That
can result in spurious change reports in which the reporter refer to
the enum 1/ where it should refer to enum 2/ or vice versa.

Intrinsically, the enum 1/ and enum 2/ are different because one
essentially has a name (provided by a typedef) and the second does
not.  One is anonymous whereas the second is not, essentially.

At the moment, libabigail supports typedef-named anonymous classes.
But it doesn't support this concept for enums.

This patch extends that concept to enums as well.  It makes it so that
any anonymous type can now by typedef-named.  In that case, the type
now looks like it has a name which is the typedef name.  The
information about the typedef naming a given type is kept and
serialized into abixml.

Thus with this patch, the enum in 1/ is now considered (canonically)
different from enum 2/.  So there is no possible confusion once the
type is serialized into abixml.

	* include/abg-fwd.h (scope_anonymous_or_typedef_named)
	(is_anonymous_or_typedef_named): Declare new functions.
	* include/abg-ir.h (decl_base::set_has_anonymous_parent): Remove
	declaration.
	(decl_base::{get,set}_naming_typedef): Declare new member
	functions.
	* src/abg-ir.cc (update_qualified_name): Define static function.
	(decl_base::priv::naming_typedef_): Define new data member.
	(decl_base::priv::has_anonymous_parent_): Remove data member.
	(decl_base::priv::priv): Adjust constructor.
	(decl_base::get_has_anonymous_parent): Rather than storing a flag
	for this, dynamically look at if the scope is anonymous.
	(decl_base::set_has_anonymous_parent): Remove definition.
	(decl_base::{get,set}_naming_typedef): Define new member
	functions.
	(scope_anonymous_or_typedef_named)
	(is_anonymous_or_typedef_named): Define new functions.
	(get_decl_name_for_comparison): Define new sub-routine for the
	decl_base overload of equals.
	(equals): In the overload for decl_base, use the new
	get_decl_name_for_comparison.  It helps to ensure that all
	anonymous decls of the same kind have the same name for the
	purpose of comparison.  It also ensures that non anonymous decls
	that are part of anonymous scopes should be compared only by
	looking at their non-qualified names.  In the overload for
	class_or_union, adjust.
	(scope_decl::add_member_decl): No more need to flag the fast that
	the parent scope is anonymous here.
	(get_debug_representation): Fix a thinko.
	(class_or_union::get_naming_typedef): Remove member function as
	it's now handled by decl_base::get_naming_typedef.
	* src/abg-dwarf-reader.cc (build_typedef_type): When a typedef is
	a naming typedef, then mark the named decl as being typedef-named.
	(maybe_canonicalize_type): Delay canonicalization of anonymous
	types because they can be typedef-named later.
	* src/abg-reader.cc (read_naming_typedef_id_string)
	(maybe_set_naming_typedef): Define new static function.
	(build_class_decl): Use it here, rather than reading the
	"naming-typedef-id" by hand.
	(build_enum_type_decl, build_union_decl): Read the
	"naming-typedef-id" property.
	* src/abg-writer.cc (write_naming_typedef): Make this accept
	decl_base_sptr, rather than just class_decl_sptr.
	(write_enum_type_decl): Write the naming-typedef-id property if
	needed.
	* tests/data/test-abidiff-exit/test-PR28316-report.txt: New test
	reference output.
	* tests/data/test-abidiff-exit/test-PR28316-v{0,1}.cc: Source code
	of new binary test input.
	* tests/data/test-abidiff-exit/test-PR28316-v{0,1}.o: New binary
	test input files.
	* tests/data/Makefile.am: Add the new test files to the source
	distribution.
	* tests/test-abidiff-exit.cc: Add the new test files above to this
	harness.
	* tests/data/test-annotate/libtest23.so.abi: Adjust.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-diff-dwarf/test15-enum-report.txt: Likewise.
	* tests/data/test-diff-filter/test19-enum-report-1.txt: 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/test30-pr18904-rvalueref-report2.txt:
	Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/PR24690/PR24690-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.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/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-09-21 16:37:44 +02:00
Dodji Seketeli
6dc5e281da abipkgdiff: Fix showing added/removed files
When two packages are different just because one adds or removes
binaries -- and no binary have any ABI change otherwise, abipkgdiff
quits early and doesn't report the added and removed binaries.

This patch fixes the issue by reporting added/removed binaries even
when no ABI comparison took place.

	* tools/abipkgdiff.cc (compare_prepared_userspace_packages): Do
	not return early if there are no binaries to compare.  Also add
	more verbose messages.
	* tests/data/test-diff-pkg/libxcrypt-4.1.1-6.el8.x86_64--libxcrypt-4.1.1-6.el8.x86_64-output-1.txt:
	New reference output file.
	* tests/data/test-diff-pkg/libxcrypt-4.1.1-6.el8.x86_64--libxcrypt-compat-4.4.18-3.el9.x86_64-report-1.txt:
	New reference output file.
	* tests/data/test-diff-pkg/libxcrypt-4.1.1-6.el8.x86_64.rpm: New
	binary input file.
	* tests/data/test-diff-pkg/libxcrypt-4.4.18-3.el9.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/libxcrypt-compat-4.4.18-3.el9.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/libxcrypt-compat-debuginfo-4.4.18-3.el9.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/libxcrypt-debuginfo-4.1.1-6.el8.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/libxcrypt-debuginfo-4.4.18-3.el9.x86_64.rpm: Likewise.
	* tests/data/Makefile.am: Add the new testing files to source
	distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add these binary packages
	to this testing harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-09-20 09:12:00 +02:00
Dodji Seketeli
190350a35f Bug 27985 - abidiff: bad array types in report
Reporting the change in array type exhibits a glitch in the type name.
As the bug report says:

	The resulting abidiff output contains:

	                type of 'int numbers[2]' changed:
			 type name changed from 'void[2]' to 'void[3]'
			 array type size changed from 64 to 96
			 array type subrange 1 changed length from 2 to 3

	instead of

	                type of 'int numbers[2]' changed:
			 type name changed from 'int[2]' to 'int[3]'
			 array type size changed from 64 to 96
			 array type subrange 1 changed length from 2 to 3

The problem comes from array_type_def::get_qualified_name() where we
fail to generate a "new" qualified name once the type of the array is
canonicalized.

Fixed thus.

	* src/abg-ir.cc (array_type_def::get_qualified_name): Use the
	cache for temporary qualified names when the type is not yet
	canonicalized.  That way, the cache for (non-temporary) qualified
	names is used only for canonicalized types.
	* tests/data/test-abidiff/test-PR27985-report.txt: Reference
	output for the new test.
	* tests/data/test-abidiff/test-PR27985-v{0,1}.c: Source code for
	the new test binary inputs.
	* tests/data/test-abidiff/test-PR27985-v{0,1}.o: New test binary inputs.
	* tests/data/test-abidiff/test-PR27985-v{0,1}.o.abi: New test
	abixml input.
	* tests/data/Makefile.am: Add the new test materials above to
	source distribution.
	* tests/test-abidiff.cc (specs): Add the tests above to the harness.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Adjust.
	* tests/data/test-abidiff-exit/qualifier-typedef-array-report-1.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-09-03 11:08:01 +02:00
Dodji Seketeli
39ba859603 Bug 27236 - Fix the canonical type propagation optimization
While working on another bug, it turned out the initial fix for the
bug https://sourceware.org/bugzilla/show_bug.cgi?id=27236 was just
papering over the real issue.

I think the real issue is that "canonical type propagation"
optimization was being done even in cases where it shouldn't have been
done.  This patch recognizes the limits of that optimization and avoid
performing it when we are off limits.

So here is what that optimization is.  The text below is also present
in the comments in the source code.  I am putting it here to explain
the context.

During the canonicalization of a type T (which doesn't yet have a
canonical type), T is compared structurally (member-wise) against a
type C which already has a canonical type.  The comparison expression
is C == T.

During that structural comparison, if a subtype of C (which also
already has a canonical type) is structurally compared to a subtype of
T (which doesn't yet have a canonical type) and if they are equal,
then we can deduce that the canonical type of the subtype of C is the
canonical type of the subtype of C.

Thus, we can canonicalize the sub-type of the T, during the
canonicalization of T itself.  That canonicalization of the sub-type
of T is what we call "propagating the canonical type of the sub-type
of C onto the sub-type of T".  It's also called "on-the-fly
canonicalization".  It's on the fly because it happens during a
comparison -- which itself happens during the canonicalization of T.

So this is the general description of the "canonical type propagation
optimization".

Now we must recognize the limits of that optimization.  Said
otherwise, there is a case when a type is *NOT* eligible to this
canonical type propagation optimization.

The reason why a type is deemed NON-eligible to the canonical type
propagation optimization is that it "depends" on a recursively present
type.  Let me explain.

Suppose we have a type T that has sub-types named ST0 and ST1.
Suppose ST1 itself has a sub-type that is T itself.  In this case, we
say that T is a recursive type, because it has T (itself) as one of
its sub-types:

  T
  +-- ST0
  |
  +-- ST1
  |    +
  |    |
  |    +-- T
  |
  +-- ST2

ST1 is said to "depend" on T because it has T as a sub-type.  But
because T is recursive, then ST1 is said to depend on a recursive
type.  Notice however that ST0 does not depend on any recursive type.

Now suppose we are comparing T to a type T' that has the same
structure with sub-types ST0', ST1' and ST2'.  During the
comparison of ST1 against ST1', their sub-type T is compared
against T'.  Because T (resp. T') is a recursive type that is
already being compared, the comparison of T against T' (as a
subtypes of ST1 and ST1') returns true, meaning they are
considered equal.  This is done so that we don't enter an infinite
recursion.

That means ST1 is also deemed equal to ST1'.  If we are in the
course of the canonicalization of T' and thus if T (as well as as
all of its sub-types) is already canonicalized, then the canonical
type propagation optimization will make us propagate the canonical
type of ST1 onto ST1'.  So the canonical type of ST1' will be
equal to the canonical type of ST1 as a result of that
optmization.

But then, later down the road, when ST2 is compared against ST2',
let's suppose that we find out that they are different. Meaning
that ST2 != ST2'.  This means that T != T', i.e, the
canonicalization of T' failed for now.  But most importantly, it
means that the propagation of the canonical type of ST1 to ST1'
must now be invalidated.  Meaning, ST1' must now be considered as
not having any canonical type.

In other words, during type canonicalization, if ST1' depends on a
recursive type T', its propagated canonical type must be
invalidated (set to nullptr) if T' appears to be different from T,
a.k.a, the canonicalization of T' temporarily failed.

This means that any sub-type that depends on recursive types and
that has been the target of the canonical type propagation
optimization must be tracked.  If the dependant recursive type
fails its canonicalization, then the sub-type being compared must
have its propagated canonical type cleared.  In other words, its
propagated canonical type must be cancelled.

This concept of cancelling the propagated canonical type when needed
is what this patch introduces.

New data members have been introduced to the environment::priv private
structure.  Those are to keep track of the stack of sub-types being
compared so that we can detect if a candidate to the canonical type
propagation optimization depends on a recursive type.

There is also a data structure in there to track the targets of the
canonical type propagation optimization that "might" need to see their
propagated canonical types be cancelled.

Then new functions have been introduced to detect when a type depends
on a recursive type, to cancel or confirm propagated canonical types
etc.

In abg-ir.cc, The RETURN* macros used in the equals() overloads have
been factorized using the newly introduced function templates
return_comparison_result().  This now contains the book keeping that
was previously done (in the RETURN* macros) to detect recursive cycles
in the comparison, as well as triggering the canonical type
propagation.  This i also where the logic of properly limiting the
optimization is implemented now.

	* include/abg-ir.h (pointer_set): This typedef is now for an
	unordered_set<uintptr_t> rather than an unordered_set<size_t>.
	(environment::priv_): Make this public so that code in free form
	function from abg-ir.cc can access it.
	* src/abg-ir-priv.h (struct type_base::priv): Move this private
	structure here, from abg-ir.cc.
	(type_base::priv::{depends_on_recursive_type_,
	canonical_type_propagated_}): Added these two new data members.
	(type_base::priv::priv): Initialize the two new data members.
	(type_base::priv::{depends_on_recursive_type,
	set_depends_on_recursive_type,
	set_does_not_depend_on_recursive_type, canonical_type_propagated,
	set_canonical_type_propagated, clear_propagated_canonical_type}):
	Define new member functions.
	(struct environment::priv): Move this struct here, from abg-ir.cc.
	(environment::priv::{types_with_non_confirmed_propagated_ct_,
	left_type_comp_operands_, right_type_comp_operands_}): New data
	members.
	(environment::priv::{mark_dependant_types,
	mark_dependant_types_compared_until, confirm_ct_propagation,
	collect_types_that_depends_on, cancel_ct_propagation,
	remove_from_types_with_non_confirmed_propagated_ct}): New member
	functions.
	* src/abg-ir.cc (struct environment::priv, struct)
	(type_base::priv, struct class_or_union::priv): Move these struct
	to include/abg-ir-priv.h.
	(push_composite_type_comparison_operands)
	(pop_composite_type_comparison_operands)
	(mark_dependant_types_compared_until)
	(maybe_cancel_propagated_canonical_type): Define new functions.
	(notify_equality_failed, mark_types_as_being_compared): Re-indent.
	(is_comparison_cycle_detected, return_comparison_result): Define
	new function templates.
	(RETURN_TRUE_IF_COMPARISON_CYCLE_DETECTED): Define new macro.
	(equals(const function_type& l, const function_type& r)): Redefine
	the RETURN macro using the new return_comparison_result function
	template.  Use the new RETURN_TRUE_IF_COMPARISON_CYCLE_DETECTED
	and mark_types_as_being_compared functions.
	(equals(const class_or_union& l, const class_or_union&, change_kind*)):
	Likewise.
	(equals(const class_decl& l, const class_decl&, change_kind*)):
	Likewise.  Because this uses another equal() function to compare
	the class_or_union part the type, ensure that no canonical type
	propagation occurs at that point.
	(types_are_being_compared): Remove as it's not used anymore.
	(maybe_propagate_canonical_type): Use the new
	environment::priv::propagate_ct() function here.
	(method_matches_at_least_one_in_vector): Ensure the
	right-hand-side operand of the equality stays on the right.  This
	is important because the equals() functions expect that.
	* src/abg-reader.cc (build_type): Ensure all types are
	canonicalized.
	* tests/data/test-diff-dwarf/PR25058-liblttng-ctl-report-1.txt:
	Adjust.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-08-11 17:39:11 +02:00
Dodji Seketeli
46b1ab08b0 Bug 27995 - Self comparison error from abixml file
There are several self comparison issues uncovered by comparing the
file test-PR27995.abi (provided in the bug report) against itself.
This patch address them all as well as the regressions induced on some
of the test suite and then and updates the other reference test suite
output that need it.

In the equals overload for decl_base, we compare the non-internal
versions of qualified decl names.  For var_decls of anonymous class or
union types, the non-internal version is the flat-representation of
the type.  Thus a benign change in a data member name of the anonymous
type might cause the equals function to consider the var_decls to be
wrongly different.  The internal version of the qualified decl name
should return a name that is stable for types, irrespective of these
benign variations.  The patch thus makes the equals overload for
decl_base to compare internal versions of qualified decl names instead.

The patch ensures that enum_type_decl::get_pretty_representation
return and internal pretty representation that is "stable" for
anonymous types.  Basically, all anonymous enums will have the same of
name that looks like "__anonymous_enum__".  This is to ensure two
things: first, that all anonymous enums are compared against each
other during type canonicalization, ensuring that when two anonymous
enums are canonically different, it really is because of changes in
their enumerators or basic type, not because of anything having to do
with their artificial names.  Second, that in the equals overload for
decl_base, their internal qualified name always compare equal.  This
nullifies the risk of having anonymous types compare different because
of their (non existent) name.  This is because libabigail's dwarf
reader assigns artificial unique names to anonymous types, so we don't
want to use these during actual type comparison.

We do something similar for class_decl::get_pretty_representation and
union_decl::get_pretty_representation where the pretty internal
representation for class/union decl would now be
__anonymous_{struct,union}__.

The patch scouts the uses of get_pretty_representation() to make sure
to use avoid using the internal-form of the pretty representations
when it's not warranted.  It also updates the doxygen comments of the
overloads of that function.

In the abixml reader, we were wrongly canonicalizing array types
early, even before they were fully created.  The was leading to
spurious type chances down the road.

The patch also fixes the caching of the name of function types by
making it consistent with caching of the names of the other types of
the system.  The idea is that we don't cache the name of a function
type until it's canonicalize.  This is because the type might be
edited during its pre-canonicalization life time; and that editing
might change its name.  However once the type is canonicalized, it
becomes immutable.  At that point we can cache its name, for
performance purposes.  Note that we need to do that both for the
"internal version" of the type name (used for canonilization purposes)
and the "non-internal version" one, which is used for other purposes.

This caching scheme wasn't respected for function types, so we were
caching a potentially wrong name for the type after its
canonicalization.

Last but not least, there is a problem that makes canonical type
comparison different from structural type comparison.
Let's consider these two declarations:

    typedef int FirstInt;
    typedef int SecondInt;

Now, consider these two pointer types: FirstInt* and SecondInt*;
These two pointer types are canonically different because they have
different type names.  This is because during type canonicalization,
types with the same "pretty representation" are compared against each
other.  So types with different type names will certainly have
different pretty representations and won't be compared; they are thus
going to have different canonical types.

However, FirstInt* and SecondInt* do compare equal, structurally,
because the equals overload for pointer_type_def compares the
pointed-to types of pointers by peeling off typedefs.  So, here, as
both pointed-to types are 'int' when the typedefs are peeled off, the
two pointers structurally compare equal.  This discrepancy between
structural and canonical equality introduces subtle and spurious type
changes depending on the order in which types are canonicalized.  For
instance:

    struct {FirstInt* m0;};   /* First type.  */

    struct {SecondInt* m0;};  /* Second type. */

If FirstInt* and SecondInt* are canonicalized before their containing
anonymous types, then the two anonymous types will compare different
(because FirstInt* and SecondInt* compare different) and have
different canonical types.  If, however, the anonymous types are
canonicalized before FirstInt* and SecondInt*, then will compare equal
because FirstInt* and SecondInt* are structurally equivalent.
FirstInt* and SecondInt* will be canonicalized latter and have
different canonical types (because they have different type names)
despite being structurally equivalent.

The change in the order of canonicalization can happen when
canonicalizing types from a corpus coming from DWARF as opposed to
canonicalizing types from a corpus coming from abixml.

The patch fixes this discrepancy by not peeling off typedefs from the
pointed-to types when comparing pointers.  Note that this makes us
regress on bug https://sourceware.org/bugzilla/show_bug.cgi?id=27236,
where the typedef peeling was introduced.  In hindsight, introducing
that typedef peeling was a mistake.  I'll try to address that bug
again in a subsequent patch.

	* doc/manuals/abidiff.rst: Add documentation for the --debug
	option.
	* src/abg-ir.cc (equals): In the overload for decl_base consider
	the internal version of qualified decl name.  In the overload for
	pointer_type_def do not peel typedefs off from the compared
	pointed-to types.  In the overload for typedef_decl compare the
	typedef as a decl as well.  In the overload for var_decl, compare
	variables that have the same ELF symbols without taking into
	account their qualified name, rather than their name.  Stop
	comparing data member without considering their names.
	In the overload for class_or_union, when a decl-only class that is
	ODR-relevant is compared against another type, assume that
	equality if names are equal.  This is useful in environments where
	some TUs are ODR-relevant and others aren't.
	(*::get_pretty_representation): Update doxygen comments.
	(enum_type_decl::get_pretty_representation): Return an internal
	pretty representation that is stable across all anonymous enums.
	(var_decl::get_anon_dm_reliable_name): Use the non-internal pretty
	representation for anonymous data members.
	(function_type::priv::temp_internal_cached_name_): New data
	member.
	(function_type::get_cached_name): Cache the internal name after
	the function type is canonicalized.  Make sure internal name and
	non-internal name are cached separately.
	(class_or_union::find_anonymous_data_member): Look for the anonymous
	data member by looking at its non-internal name.
	({class, union}_decl::get_pretty_representation): Use something like "class
	__anonymous_{union,struct}__" for all anonymous classes, so that they can
	all be compared against each other during type canonicalization.
	(type_has_sub_type_changes): Use non-internal pretty
	representation.
	(hash_type_or_decl, function_decl_is_less_than:): Use internal
	pretty representation for comparison here.
	* src/abg-reader.cc (read_context::maybe_canonicalize_type): Don't
	early canonicalize array types.
	* src/abg-writer.cc (annotate): Use non-internal pretty
	representation.
	* tests/data/test-diff-filter/test-PR27995-report-0.txt: New
	reference report.
	* tests/data/test-diff-filter/test-PR27995.abi: New test input
	abixml file.
	* tests/data/Makefile.am: Add test-PR27995.abi,
	test-PR27995-report-0.txt to the source distribution.
	* tests/data/test-annotate/libtest23.so.abi: Adjust.
	* tests/data/test-diff-dwarf/test6-report.txt: Adjust.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Adjust.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt: Adjust.
	* tests/data/test-diff-filter/test41-report-0.txt: Adjust.
	* tests/data/test-diff-filter/test43-decl-only-def-change-leaf-report-0.txt: Adjust.
	* tests/data/test-diff-filter/test8-report.txt: Adjust.
	* tests/data/test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm--libICE-1.0.9-2.el7.x86_64.rpm-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Adjust.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt:
	Adjust.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Adjust.
	* tests/data/test-diff-suppr/test39-opaque-type-report-0.txt: Adjust.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi: Adjust.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Adjust.
	* tests/data/test-read-dwarf/libtest23.so.abi: Adjust.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Adjust.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Adjust.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Adjust.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.
	* tests/test-diff-filter.cc (in_out_specs): Add the
	test-PR27995.abi to the test harness.
	* tools/abidiff.cc (options::do_debug): New data member.
	(options::options): Initialize it.
	(parse_command_line): Parse --debug.
	(main): Activate self comparison debug if the user provided
	--debug.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-08-11 17:38:14 +02:00
Giuliano Procida
cfd81dec10 PR28060 - Invalid offset for bitfields
Bitfield and other member offsets can be specified in DWARF using:

- DW_AT_data_bit_offset, or
- DW_AT_data_member_location and optionally DW_AT_bit_offset.

The code would only use the value DW_AT_data_member_location if there
was no DW_AT_bit_offset. This commit fixes this and adjusts
documentation and affected tests.

	* src/abg-dwarf-reader.cc (read_and_convert_DW_at_bit_offset):
	Update documentation.
	(die_member_offset): Treat DW_AT_bit_offset as an optional
	adjustment to DW_AT_data_member_location.
	* tests/data/test-annotate/test13-pr18894.so.abi: Update.
	* tests/data/test-annotate/test15-pr18892.so.abi: Update.
	* tests/data/test-annotate/test17-pr19027.so.abi: Update.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Update.
	* tests/data/test-annotate/test21-pr19092.so.abi: Update.
	* tests/data/test-diff-dwarf-abixml/PR25409-librte_bus_dpaa.so.20.0.abi:
	Regenerate.
	* tests/data/test-diff-pkg/libcdio-0.94-1.fc26.x86_64--libcdio-0.94-2.fc26.x86_64-report.1.txt:
	Report now empty.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Update.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Update.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Update.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Update.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Update.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Update.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Update.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Update.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-07-19 13:17:29 +02:00
Dodji Seketeli
1cfbff1b30 rhbz1951526 - SELF CHECK FAILED for 'gimp-2.10'
This is a fix for bug https://bugzilla.redhat.com/show_bug.cgi?id=1951526.

Although it's a patch for one bug, it addresses several different
issues that cause the observed self comparison failure.  As is often
the case on this kind of problems, the failure is difficult to
reproduce on a synthetic test case so I'll explain the root causes in
this commit log.

There are 4 different root causes to this problem.  As I couldn't come
up with a reduced test case for each one of them I am adding the fixes
for those 4 issues in this commit, along with a new regression test
extracted from the initial bugzilla problem report.

So, overall, the symptom we are seeing here is that when we build an
IR for the input binary gimp-2.0, save that IR into abixml, and read
back that abixml into another IR, comparing the two IR shows changes;
it should show no change whatsoever.  This is what we call in
libabigail jargon a self comparison (or self check) failure.

As alluded to in my introduction above, there appear to be 4 different
root causes for that self comparison failure.

1/ The first cause has to do with a situation about two anymous enums
that are (wrongly) considered different from an ABI point of view.
Using the debugging capabilities recently gained by libabigail, I
could notice that the two enums are:

    (gdb) p debug(&l)
    enum __anonymous_enum__ : unnamed-enum-underlying-type-32
    {
      // size in bits: 32
      // translation unit: /usr/src/debug/gimp-2.10.22-2.el9.1.aarch64/app/<artificial>-757de
      // @: 0x698fb68, @canonical: 0

      GIMP_INTERPOLATION_NONE = 0,
      GIMP_INTERPOLATION_LINEAR = 1,
      GIMP_INTERPOLATION_CUBIC = 2,
      GIMP_INTERPOLATION_NOHALO = 3,
      GIMP_INTERPOLATION_LOHALO = 4,
    };

    $1 = (abigail::ir::decl_base *) 0x698fba0
    (gdb) p debug(&r)
    enum __anonymous_enum__ : unnamed-enum-underlying-type-32
    {
      // size in bits: 32
      // translation unit: /usr/src/debug/gimp-2.10.22-2.el9.1.aarch64/app/app.c
      // @: 0xa6d83e8, @canonical: 0

      GIMP_INTERPOLATION_NONE = 0,
      GIMP_INTERPOLATION_LINEAR = 1,
      GIMP_INTERPOLATION_CUBIC = 2,
      GIMP_INTERPOLATION_NOHALO = 3,
      GIMP_INTERPOLATION_LOHALO = 4,
      GIMP_INTERPOLATION_LANCZOS = 3,
    };

    $2 = (abigail::ir::decl_base *) 0xa6d8420
    (gdb)

Note how the second enum has a new enumerator named
'GIMP_INTERPOLATION_LANCZOS', but its value is '3', which is the exact
same value of as the one of the existing enumerator
GIMP_INTERPOLATION_NOHALO.

During type canonicalization of the IR from the input binary,
libabigail (wrongly) considers these two enums as being different.
This leads to the type 'Gimp*' (or anything type indirectly using any
one of the anonymous enums above) coming from one translation unit
being considered different from a type 'Gimp*' coming from another
translation unit, just because their are not using either one version
of the anonymous enum above or the other.

This leads to a *LOT* of spurious type changes from the first IR, that
are saved into abixml.

To fix this first problem, this patch introduces "two modes" of
comparing enums. There is a binary-only mode which only looks
enumerator values, not enumerator names.  And then there is the
source-level mode which looks at both enumerator names and values when
comparing enums.  The former mode is used during type
canonicalization.  However, when a change is detected between two
enums, then the diff-IR built to describe the change is constructed
using the later mode.  Using the later mode allows to describe
precisely things like enumerator insertion/removal by referring to the
names of the added/removed enumerators.

2/ The second root cause is that a struct, say, 'struct _GimpImage'
from a translation unit is considered different from a 'struct
_GimpImage' because the DWARF reader wrongly assign them different sizes.

Here is what it looks like in the debugger:

    (gdb) p debug(&l)
    struct _GimpImage
    {  // size in bits: 384
       // definition point: ../../app/core/gimpimage.h:39:1
       // translation unit: /usr/src/debug/gimp-2.10.22-2.el9.1.aarch64/app/<artificial>-757de
       // @: 0x69b9d10, @canonical: 0

      GimpViewable parent_instance;'
      Gimp* gimp;'
      GimpImagePrivate* priv;'
    };

    $8 = (abigail::ir::type_base *) 0x69b9d10
    (gdb) p debug(&r)
    struct _GimpImage
    {  // size in bits: 0
       // definition point: :0:0
       // translation unit: /usr/src/debug/gimp-2.10.22-2.el9.1.aarch64/app/<artificial>-8813f
       // @: 0x6ac7a50, @canonical: 0

    };

Notice how the second 'struct _GimpImage' has a size of zero.

This is because when reading the DWARF, we first encounter the DIE for
the first' struct _GimpImage' and we properly build a type for it,
along with its declaration.  Then when we encounter another DIE
defining 'struct _GimpImage' again, from a different translation unit,
the DWARF reader recognizes that it's a DIE for a declaration of
'struct _GimpImage' and fails to re-use the previous definition for
'struct _GimpImage'.  So it wrongly builds declaration-only 'struct
_GimpImage' for it, hence the second struct _GimpImage with a zero
size.

Here again that creates spurious changes (after type canonicalization)
in types using struct _GimpImage.  And that is a lot of types,
including things like 'Gimp*' and the like.

The fix for this root cause issue is to change
add_or_update_class_type in the DWARF reader to recognize that we are
seeing a type declaration for which there was already a definition and
return that definition instead of creating a new declaration.

3/ The third root cause is better explained with a "screen shot".
Consider these two 'versions' of the same struct _GdkDevice from two
different translation units:

    struct _GdkDevice
    {  // size in bits: 576
       // definition point: /usr/include/gtk-2.0/gdk/gdkinput.h:98:1
       // translation unit: /usr/src/debug/gimp-2.10.22-2.el9.1.aarch64/app/<artificial>-2d0352
       // @: 0x8820530, @canonical: 0

      GObject parent_instance;'
      gchar* name; // uses canonical type '@0x6892980'
      GdkInputSource source;'
      GdkInputMode mode;'
      gboolean has_cursor; // uses canonical type '@0x688dd00'
      gint num_axes; // uses canonical type '@0x688dd00'
      GdkDeviceAxis* axes;'
      gint num_keys; // uses canonical type '@0x688dd00'
      GdkDeviceKey* keys;'
    };

    $9 = (abigail::ir::type_base *) 0x8820530
    (gdb) p debug(&r)
    struct _GdkDevice
    {  // size in bits: 576
       // definition point: /usr/include/gtk-2.0/gdk/gdkinput.h:98:1
       // translation unit: /usr/src/debug/gimp-2.10.22-2.el9.1.aarch64/app/<artificial>-1fdb18
       // @: 0x7cd71e0, @canonical: 0

      GObject parent_instance;'
      gchar* _g_sealed__name; // uses canonical type '@0x6892980'
      GdkInputSource _g_sealed__source;'
      GdkInputMode _g_sealed__mode;'
      gboolean _g_sealed__has_cursor; // uses canonical type '@0x688dd00'
      gint _g_sealed__num_axes; // uses canonical type '@0x688dd00'
      GdkDeviceAxis* _g_sealed__axes;'
      gint _g_sealed__num_keys; // uses canonical type '@0x688dd00'
      GdkDeviceKey* _g_sealed__keys;'
    };

    $10 = (abigail::ir::type_base *) 0x7cd71e0
    (gdb)

Notice how the name of the second data member 'name' was changed to
'_g_sealed_name'.  A similar scheme happens to several other data
member names.  The offsets and types of the struct _GdkDevice haven't
changed however.  So from an ABI standpoint, the two versions of that
struct are equal.  Libabigail consider them different however.
Because that type is used by tons of other types of the binary being
analyzed, this leads to lots of spurious canonical type difference
that shouldn't be there.

These three issues are magnified by the fact that the gimp binary is
compiled using "link time optimization".  That brings in a lot more
opportunities to see these underlying issues that have been there for
a long time.

4/ The fourth and last root cause issue.  When the abixml writer emits
a translation unit (TU), it keeps track of the 'non-emitted referred
to type' of the currently emitted translation unit and emits them at
the end of each TU.  For instance, if the type 'Gimp*' (pointer to
Gimp) was emitted, and yet the referred-to type 'Gimp' wasn't emitted,
the TU writer makes sure to emit the referred-to 'Gimp' type at the
end of the TU.  This has been going on for quite some time now.

The problem however is that although the non-emitted referred-to type
was referred to in this current TU, it might no have been *DEFINED* in
this TU.  In that case, it should not be emitted in this TU.

Otherwise, the TU where that type is defined in the abixml might
appear different from where it is defined in the initial binary,
leading to self comparison failures down the road.

This patch ensures that a non-emitted referred-to type is always
emitted in the TU it belongs to.

5/ After doing all this, it appears that we were forgetting to emit
some function types that were defined in TUs emitted earlier and yet
were being referred-to later.  Looking closer, I realized that we
should just emit function types seen in a given TU, regardless of the
referred-to relation.

The problem with that is that function types are special in libabigail
because there are two situation in which they are created.

Basically, a function type is created by the DWARF DIE
DW_TAG_subroutine_type.  This is for instance how pointer to functions
are represented in DWARF, namely, by a DW_TAG_pointer_type that points
to a DW_TAG_subroutine_type.  That is represented in the libabigail ir
by an instance of the abigail::ir::function_type type.  This is
represented in abixml as a 'function-type' XML element.

But then, libabigail considers that all decls have a type.  This
applies obviously for variables or data member.  Right.  But then,
libabigail considers that a function is also a decl, which has a type.
And the type of a function is a function type, represented by the same
abigail::ir::function_type.  A practical difference with the former
situation is that function decls are *NOT* represented in abixml using
a 'function-type' element.  Instead a 'function-decl' XML element uses
return type and parameter elements to represent the types involved
with a function decl.

Said otherwise, the former 'function type' concept used to represent
the type of functions in the libabigail IR is artificial.  This
artificial-ness was not explicitly expressed in libabigail.  This
patch now expresses that artificial-ness for function types.  So the
abixml writer now just decide to not emit artificial function types,
and instead, emit all the non-artificial function types instead.

This addresses this last issues by being able to emit all
non-artificial function types defined in a given TU, without having to
bother with the fact that they are referred-to or not.

Together, fixing these 5 problems fixes this reported problem.

The changes to the reference test outputs are adjustments needed
because of the abixml output indeed changes.

	* include/abg-ir.h
	(environment::use_enum_binary_only_equality): Declare
	accessors.  (type_or_decl_base::{s,g}et_is_artificial):
	Likewise.  (decl_base::{s,g}et_is_artificial): Remove
	accessors.  * src/abg-ir.cc
	(environment::priv::use_enum_binary_only_equality): Define new
	data member.
	(environment::priv::use_enum_binary_only_equality): Define
	accessors.  (type_or_decl_base::priv::is_artificial_): Define
	new data member.  It has actually moved here from
	decl_base::priv::is_artificial_.
	(type_or_decl_base::priv::priv): Initialize it.
	(type_or_decl_base::{g,s}et_is_artificial): Define accessors.
	(decl_base::is_artificial_): Move this to
	type_or_decl_base::is_artificial_.
	(maybe_adjust_canonical_type): In a given class of equivalence
	of function types, if there is one non-artificial function
	type, then the entire class of equivalence is considered
	non-artificial; so flag the canonical function type as being
	non-artificial.  (is_enumerator_present_in_enum): Define new
	static function.  (equals): Re-arrange the overload for enums
	so the order of the enumerators doesn't count in the
	comparison.  Also, two enums with different numbers of
	enumerators can still be equal, with the right redundancy.  In
	the overload for var_decl, avoid taking into account the names
	of data members in the comparison.
	(enum_type_decl::enumerator::operator==): In the binary-level
	comparison mode, only compare the value of enumerators, not
	their name.  * src/abg-comparison.cc (compute_diff): In the
	overload for enum_type_decl, if the enums compare different
	using binary-level comparison, then use source-level
	comparison to build the diff-IR.  * src/abg-dwarf-reader.cc
	(read_context::compare_before_canonicalisation): Compare enums
	using binary-level comparison.  (add_or_update_class_type): If
	we are looking at the definition of an existing declaration
	that has been already defined then use the previous
	definition, in case we are going to need to update the
	definition.  Also, update the size only if it's needed.
	(build_function_type): By default, consider the newly built
	function type as artificial.  (build_ir_node_from_die): When
	looking at a DW_TAG_subroutine_type DIE, consider the built
	function type as non-artificial.  * src/abg-reader.cc
	(read_context::maybe_check_abixml_canonical_type_stability):
	Don't consider declaration-only classes in an ODR context
	because they don't have canonical types.
	(build_function_decl): Flag the function type of the function
	as artificial.  (build_class_decl): Make sure to reuse class
	types that were already created.  * src/abg-writer.cc
	(write_translation_unit): Allow emitting empty classes.  Make
	sure referenced types are emitting in the translation unit
	where they belong.  Avoid emitting artificial function types.
	*
	tests/data/test-alt-dwarf-file/rhbz1951526/rhbz1951526-report-0.txt:
	New test reference output.  *
	tests/data/test-alt-dwarf-file/rhbz1951526/usr/bin/gimp-2.10:
	New reference test binary input.  *
	tests/data/test-alt-dwarf-file/rhbz1951526/usr/lib/debug/.dwz/gimp-2.10.22-2.el9.1.aarch64:
	Likewise.  *
	tests/data/test-alt-dwarf-file/rhbz1951526/usr/lib/debug/usr/bin/gimp-2.10-2.10.22-2.el9.1.aarch64.debug:
	Likewise.  * tests/data/Makefile.am: Add the new test files to
	source directory.  * tests/test-alt-dwarf-file.cc: Add the new
	test inputs to this test harness.  *
	tests/data/test-abidiff/test-PR18791-report0.txt: Adjust.  *
	tests/data/test-abidiff/test-enum0-report.txt: Likewise.  *
	tests/data/test-annotate/libtest23.so.abi: Likewise.  *
	tests/data/test-annotate/libtest24-drop-fns-2.so.abi:
	Likewise.  *
	tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi:
	Likewise.  * tests/data/test-annotate/test13-pr18894.so.abi:
	Likewise.  * tests/data/test-annotate/test14-pr18893.so.abi:
	Likewise.  * tests/data/test-annotate/test15-pr18892.so.abi:
	Likewise.  * tests/data/test-annotate/test17-pr19027.so.abi:
	Likewise.  *
	tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.  *
	tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.  *
	tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.  * tests/data/test-annotate/test21-pr19092.so.abi:
	Likewise.  *
	tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi:
	Likewise.  *
	tests/data/test-diff-dwarf/PR25058-liblttng-ctl-report-1.txt:
	Likewise.  * tests/data/test-diff-dwarf/test6-report.txt:
	Likewise.  *
	tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt:
	Likewise.  *
	tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt:
	Likewise.  * tests/data/test-diff-filter/test8-report.txt:
	Likewise.  *
	tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.  *
	tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt:
	Likewise.  *
	tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.  *
	tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.  *
	tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Likewise.  *
	tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.
	*
	tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Likewise.  *
	tests/data/test-read-dwarf/PR26261/PR26261-exe.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.  *
	tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Likewise.  *
	tests/data/test-read-dwarf/libtest24-drop-fns.so.abi:
	Likewise.  *
	tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* 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.  *
	tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.  * tests/data/test-read-dwarf/test21-pr19092.so.abi:
	Likewise.  *
	tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.  *
	tests/data/test-read-dwarf/test9-pr18818-clang.so.abi:
	Likewise.  *
	tests/data/test-read-write/test28-without-std-fns-ref.xml:
	Likewise.  *
	tests/data/test-read-write/test28-without-std-vars-ref.xml:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-06-09 18:43:02 +02:00
Dodji Seketeli
7a9fa3fe5a abixml reader: Fix recursive type definition handling
This should fix self comparison bug https://bugzilla.redhat.com/show_bug.cgi?id=1944088

This arose from a self comparison check failing on the library
libgvpr.so.2 from the graphviz-2.44.0-17.el9.aarch64.rpm package.

Now that we have facilities to see what type (instantiated from the
abixml representation of the libgvpr.so library) exactly the
canonicalization process is failing for, I decided to use it ;-)

I extracted the package and its associating debug info into a
directory named 'extract' and ran abidw --debug-abidiff on it:

    $ build/tool/abidw  --debug-abidiff -d extract/usr/lib/debug extract/usr/lib64/libgvpr.so.2

That yielded the output below:

    error: problem detected with type 'typedef Vmalloc_t' from second corpus
    error: canonical type for type 'typedef Vmalloc_t' of type-id 'type-id-170' changed from 'd72618' to '14a7448'
    error: problem detected with type 'Vmalloc_t*' from second corpus
    error: canonical type for type 'Vmalloc_t*' of type-id 'type-id-188' changed from 'd72ba8' to '14a7968'
    [...]

This tells me that "typedef Vmalloc_t", created from the abixml
compares different from its originating peer that was created from the
binary directly.  The same goes for the pointer type "Vmalloc_t*", etc.

Using the new debugging/logging functionalities from the command line
of the debugger, I could see that in the abixml reader,
build_typedef_decl can fail subtly when the underlying type of the
typedef refers to the typedef itself.  In that case, we need to ensure
that the typedef created by build_typedef_decl is the same one that is
used by the underlying type.  which is not the case at the moment.  At
the moment, the underlying type would create a new typedef beside the
one currently being created by build_typedef_decl.  That leads to more
than one typedef in the system to designate "typedef Vmalloc_t".  And
that wreaks havoc later down the road.

This patch arranges so that build_typedef_decl creates the typedef
"early" before the underlying type is created.  That typedef
temporarily has no underlying type.  It's registered as being the
typedef for the type-id string that identifies it in the abixml.  And
then the function goes to create the underlying type.  This
arrangement ensures that if the underlying type refers to the typedef
being created (via its type-id string), then the typedef that was
created early is effectively re-used.  This ensures that a typedef
which recursively refer to itself is properly represented.  It's only
when the underlying type is fully created that it's added to the
typedef.

Something similar is done for pointer types, in
build_pointer_type_def.

Note that to do this, the patch adjusts the typedef_decl and
pointer_type_def classes so that they can be created with no
underlying/pointed-to types.  The underlying/pointed-to type can thus
be added later.

I believe this patch is the minimal patch necessary to fix this issue.
The graphviz RPM is added to the regression test suite for good
measure.

After visual inspection, I realized that there are other types besides
typedef and pointer types that exhibit the same class of problem even
if they are not involved in this issue on this particular binary.  A
subsequent patch is going to address the problem for those types,
namely, qualified and reference types.

	* include/abg-ir.h (pointer_type_def::pointer_type_def): Declare a
	constructor with no pointed-to type.
	(pointer_type_def::set_pointed_to_type): Declare new method.
	(typedef_decl::typedef_decl): Declare a constructor with no
	underlying type.
	* src/abg-ir.cc (pointer_type_def::pointer_type_def): Define a
	constructor with no pointed-to type.  The pointed-to type can thus
	later be set when it becomes available.
	(pointer_type_def::set_pointed_to_type): Define new method.
	(pointer_type_def::get_qualified_name): Make this work on a
	pointer type that (momentarily) has no pointed-to type.
	(typedef_decl::typedef_decl): Define a constructor with no
	underlying type.
	(typedef_decl::get_size_in_bits): Make this work on a typedef that
	has (momentarily) no underlying type.
	(typedef_decl::set_underlying_type): Update the size and alignment
	of the typedef from its new underlying type.
	* src/abg-reader.cc (build_pointer_type_def): Construct the
	pointer type early /BEFORE/ we even try to construct its
	pointed-to type.  Associate this incomplete type with the type-id.
	Then try to construct the pointed-to type.  During the
	construction of the pointed-to type, if this pointer is needed
	(due to recursion) then the incomplete pointer type can be used,
	leading to just one pointer type used (recursively) as it should
	be.
	(build_typedef_decl): Likewise for building typedef type early
	without its underlying type so that it can used by the underlying
	type if needed.
	* tests/data/test-diff-pkg/graphviz-2.44.0-18.el9.aarch64-self-check-report-0.txt:
	New test reference output.
	* tests/data/test-diff-pkg/graphviz-2.44.0-18.el9.aarch64.rpm: New
	binary test input.
	* tests/data/test-diff-pkg/graphviz-debuginfo-2.44.0-18.el9.aarch64.rpm: Likewise.
	* tests/data/Makefile.am: Add the new test material above to
	source distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the test inputs above
	to this test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-05-25 12:39:57 +02:00
Matthias Maennich
ff4b4a56b4 symtab/dwarf-reader: allow hinting of main symbols for aliases
In case of aliased symbols, the "main symbol" cannot be deduced from
the symtab as this solely contains a name->addr mapping and aliases
are represented by multiple names resolving to the same address.
Therefore the main symbol can only be picked rather randomly and
unpredictable.

Unlike DWARF, which contains a single symbol entry for only the main
symbol. Hence we can (late) detect the main symbol. Exploiting that
property allows to correct the addr->symbol lookup in the symtab to
return the correct main symbol and it also allows to correct the aliased
symbols to maintain the correct main symbol.

This patch adds the `update_main_symbol` functionality to `elf_symbol`
to update the main symbol by name (ELF symbols need unique names) and
adds `update_main_symbol` to `symtab` that makes use of said new method.

When we discover a main symbol during DWARF reading, we instruct the
symtab to update the mapping.

This creates consistent representations across different builds of the
same binary with the same ABI by pinning down the main symbol to the
defined one. Knowing the main symbol also helps to keep the correct
dwarf information in the representation in the presence of symbol
suppressions. A later patch will address that.

Some test cases in tests/data need adjustment and they have all been
verified to be valid changes.

- main symbol changed for various elf symbols
  - test-annotate/test15-pr18892.so.abi
  - test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi
  - test-annotate/test3.so.abi
  - test-read-dwarf/test15-pr18892.so.abi
  - test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi
  - test-read-dwarf/test3.so.abi
  - test-read-dwarf/test3.so.hash.abi

- due to main symbol changes, the symbol diff needs to be corrected
  - test-diff-dwarf/test12-report.txt
  - test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt
  - test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt

- the test scenario needed adjustments as the main symbol changed
  - test-diff-suppr/test23-alias-filter-4.suppr
  - test-diff-suppr/test23-alias-filter-report-0.txt
  - test-diff-suppr/test23-alias-filter-report-2.txt

As usual, the complete changelog follows.

	* include/abg-ir.h (elf_symbol::update_main_symbol): New method.
	* include/abg-symtab-reader.h (symtab::update_main_symbol): New method.
	* src/abg-dwarf-reader.cc
	(build_var_decl): Hint symtab about main symbol discovered in DWARF.
	(build_function_decl): Likewise.
	* src/abg-ir.cc (elf_symbol::get_main_symbol): Lock the weak_ptr
	  on access in both overloads.
	(update_main_symbol): New method to allow updating the main symbol.
	* src/abg-symtab-reader.cc (symtab::update_main_symbol): New method.
	* data/Makefile.am: Add new test data files.
	* tests/data/test-annotate/test15-pr18892.so.abi: Updated test file.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-annotate/test2.so.abi: Likewise.
	* tests/data/test-annotate/test3.so.abi: Likewise.
	* tests/data/test-diff-dwarf/test12-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-4.suppr: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-report-2.txt: Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.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/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise.
	* tests/data/test-read-dwarf/test3.so.abi: Likewise.
	* tests/data/test-read-dwarf/test3.so.hash.abi: Likewise.
	* tests/data/test-symtab/basic/aliases.c: New test source file.
	* tests/data/test-symtab/basic/aliases.so: Likewise.
	* tests/test-symtab.cc (Symtab::AliasedFunctionSymbols): New test case.
	(Symtab::AliasedVariableSymbols): Likewise.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Reviewed-by: Dodji Seketeli <dodji@seketeli.org>
Signed-off-by: Matthias Maennich <maennich@google.com>
2021-04-02 15:54:23 +02:00
Dodji Seketeli
2eefd17276 Bug 27569 - abidiff misses a function parameter addition
Adding or deleting function parameters are changes that have not yet
been categorized in the comparison engine.  As a result, those changes
can be considered harmless and thus be filtered out.  Oops.

This patch categorizes function addition and removal as
FN_PARM_ADD_REMOVE_CHANGE_CATEGORY, which is a new category being
introduced.  Changes in this category are considered harmful and are
thus always reported by default.

	* include/abg-comparison.h (enum diff_category): Add a new
	FN_PARM_ADD_REMOVE_CHANGE_CATEGORY enumerator and adjust the
	following enumerator values.  Update the EVERYTHING_CATEGORY
	accordingly.
	(function_type_diff::{sorted_deleted_parms, sorted_added_parms}):
	Add new member functions.
	* src/abg-comparison.cc
	(function_type_diff::{sorted_deleted_parms, sorted_added_parms}):
	Define new accessors.
	(get_default_harmful_categories_bitmap):
	Consider changes of the category
	FN_PARM_ADD_REMOVE_CHANGE_CATEGORY as harmful.
	(operator<<(ostream& o, diff_category c)): Support the new
	FN_PARM_ADD_REMOVE_CHANGE_CATEGORY while serializing a category
	bitmap.
	* src/abg-comp-filter.cc
	(has_added_or_removed_function_parameters): Define new static
	function.
	(categorize_harmful_diff_node): Categorize diff nodes representing
	function parameter addition or removal as
	FN_PARM_ADD_REMOVE_CHANGE_CATEGORY.
	* tests/data/test-diff-filter/test-PR27569-report-0.txt: New test
	reference output.
	* tests/data/test-diff-filter/test-PR27569-v{0,1}.abi: New test inputs.
	* tests/data/Makefile.am: Add the new test inputs to the source
	distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the new test
	inputs to this test harness.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt:
	Adjust.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt:
	Likewise.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64--libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-03-29 12:34:48 +02:00
Dodji Seketeli
40aab37cf0 dwarf-reader: Support more DWARF-5 type DIEs
When analyzing DWARF-5 some binaries, is_type_tag chokes on the new
DWARF-5 type DIEs it doesn't know about.

This patch teaches it about them.

	* src/abg-dwarf-reader.cc (is_type_tag): Support
	DW_TAG_coarray_type, DW_TAG_atomic_type and DW_TAG_immutable_type.
	* tests/data/test-diff-pkg/elfutils-debuginfo-0.183-1.el9.x86_64.rpm:
	Add new binary test input.
	* tests/data/test-diff-pkg/elfutils-libs-debuginfo-0.183-1.el9.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/elfutils-libs-0.183-1.el9.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/elfutils-libs-debuginfo-0.183-1.el9.x86_64-self-check-report-0.txt:
	Add new reference test output.
	* tests/test-diff-pkg.cc (in_out_specs): Add the test inputs above
	to the harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-03-18 13:41:18 +01:00
Dodji Seketeli
77bc4b7b15 Don't consider type name when comparing typedefs
This is from a problem report originating from Red Hat bugzilla at
https://bugzilla.redhat.com/show_bug.cgi?id=1925876

I some C programs, the same type can be defined more than once in a
binary, as there is no "One Definition Rule[1]" in C.

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

The definition of those two types can be slightly different and yet be
equivalent.

For instance, the data member of a struct S might be defined once as
having a type which is a typedef Foo of, say, "long int" and that
struct S might be defined again elsewhere with a data member of type
typedef Bar of "long int" as well.

With the current code, because Foo and Bar have different names, they
are are going to compare different; so the two struct S are doing to
compare different even though they are equivalent.

Down the road, this is likely going to imply that the several 'struct
S' that are declaration-only will not be resolved as being
declarations of the definition of "struct S", because they is more
than one such definition, and those definitions are different.

This is going to lead to spurious (and hard to debug) type differences
that are going to be detected and reported by libabigail later down
the road.

This patch addresses the problem by not taking typedef names into
account when comparing typedefs before canonicalization.  That allows
the comparison of classes and structs that happens during the
resolution of declaration-only classes to correctly deduce their
equivalence even in cases like the one exposed above.  It thus reduces
the amount of declaration-only classes that are unnecessarily
considered to be different from the definition they ought to equal.

	* include/abg-ir.h (maybe_compare_as_member_decls): Declare new
	function.  Make it a friend of class decl_base.
	* src/abg-dwarf-reader.cc (maybe_canonicalize_type): Don't early
	canonicalize typedefs because they can be "part" of a type that is
	not yet completed, especially considering that class declaration
	resolution is part of type building, stricto sensu.
	* src/abg-ir.cc (maybe_compare_as_member_decls): Factorize this
	out of ...
	(equals): ... the overload for decl_base.  Use it in the overload
	for typedef_decl.
	* tests/data/test-diff-pkg/nmap-7.70-5.el8_testjcc.x86_64-self-check-report-0.txt:
	New test reference output.
	* tests/data/test-diff-pkg/nmap-7.70-5.el8_testjcc.x86_64.rpm: New
	binary input.
	* tests/data/test-diff-pkg/nmap-debuginfo-7.70-5.el8_testjcc.x86_64.rpm: Likewise.
	* tests/data/Makefile.am: Add these new testing material to source
	distribution.
 	* tests/test-diff-pkg.cc (in_out_specs): Add the new test input to
	the harness.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-0.txt:
	Adjust.
	* tests/data/test-diff-suppr/test39-opaque-type-report-0.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-02-11 17:23:42 +01:00
Dodji Seketeli
a8c0199df5 Use generic internal type name to canonicalize anonymous enums
This is from the problem report in Red Hat bugzilla

    https://bugzilla.redhat.com/show_bug.cgi?id=1924624
    "comparing 'libpinyin.so.13.0.0' to itself wrongly yielded result"

During the canonicalization of an anonymous enum, the algorithm uses
its internal pretty representation to limit the number of types to
compare it to.  That internal pretty representation is based on its
type name.

For anonymous types, the type name is not unique; it's constructed for
internal purposes that are different from the purpose of
canonicalization.  So using that in the pretty representation might
negatively impact the accuracy of the canonicalization; it might make
it so that two anonymous in the same namespace types might wrongly be
considered canonically different.

To fix that, this change makes the internal pretty representation of
anonymous enum types essentially be "enum
<namespace-name>::__anonymous_enum__".

This is on part with what is done for unions and classes in commit:
    005ab5c9 Use flat representation to canonicalize anonymous classes and unions

	* src/abg-ir.cc (has_generic_anonymous_internal_type_name) :
	Define new static function.
	(get_generic_anonymous_internal_type_name): Use it here.
	(decl_base::get_pretty_representation): For internal purposes,
	build an anonymous name that is stable.
	* tests/data/test-annotate/test21-pr19092.so.abi: Adjust.
	* tests/data/test-diff-pkg/PR24690/PR24690-report-0.txt: Adjust.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt: Adjust.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Adjust.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-02-10 20:03:11 +01:00
Giuliano Procida
89de572d7b abidiff: do not qualify member names in diff report
Bug 26012 - abidiff: do not emit qualified name for data members

The enclosing struct (or union or class) is given by the surrounding
diff context. This change eliminates a lot of repetition in the diff
report.

	* src/abg-reporter-priv.cc (represent_data_member): Do not
	qualify member names. (represent): Do not qualify member names.
	* tests/data/test-abicompat/test0-fn-changed-report-0.txt: Refresh.
	* tests/data/test-abicompat/test0-fn-changed-report-2.txt: Refresh.
	* tests/data/test-abicompat/test5-fn-changed-report-0.txt: Refresh.
	* tests/data/test-abicompat/test5-fn-changed-report-1.txt: Refresh.
	* tests/data/test-abicompat/test6-var-changed-report-0.txt: Refresh.
	* tests/data/test-abicompat/test6-var-changed-report-1.txt: Refresh.
	* tests/data/test-abicompat/test7-fn-changed-report-0.txt: Refresh.
	* tests/data/test-abicompat/test7-fn-changed-report-1.txt: Refresh.
	* tests/data/test-abicompat/test7-fn-changed-report-2.txt: Refresh.
	* tests/data/test-abicompat/test8-fn-changed-report-0.txt: Refresh.
	* tests/data/test-abicompat/test9-fn-changed-report-0.txt: Refresh.
	* tests/data/test-abidiff-exit/qualifier-typedef-array-report-1.txt:
	Refresh.
	* tests/data/test-abidiff-exit/test-fun-param-report.txt: Refresh.
	* tests/data/test-abidiff-exit/test-headers-dirs/test-headers-dir-report-2.txt:
	Refresh.
	* tests/data/test-abidiff-exit/test-leaf-cxx-members-report.txt:
	Refresh.
	* tests/data/test-abidiff-exit/test-leaf-peeling-report.txt: Refresh.
	* tests/data/test-abidiff-exit/test-leaf-redundant-report.txt: Refresh.
	* tests/data/test-abidiff-exit/test-member-size-report0.txt: Refresh.
	* tests/data/test-abidiff-exit/test-member-size-report1.txt: Refresh.
	* tests/data/test-abidiff-exit/test-net-change-report0.txt: Refresh.
	* tests/data/test-abidiff/test-PR18791-report0.txt: Refresh.
	* tests/data/test-abidiff/test-qual-type0-report.txt: Refresh.
	* tests/data/test-abidiff/test-struct0-report.txt: Refresh.
	* tests/data/test-abidiff/test-struct1-report.txt: Refresh.
	* tests/data/test-diff-dwarf/PR25058-liblttng-ctl-report-1.txt:
	Refresh.
	* tests/data/test-diff-dwarf/test0-report.txt: Refresh.
	* tests/data/test-diff-dwarf/test1-report.txt: Refresh.
	* tests/data/test-diff-dwarf/test10-report.txt: Refresh.
	* tests/data/test-diff-dwarf/test11-report.txt: Refresh.
	* tests/data/test-diff-dwarf/test13-report.txt: Refresh.
	* tests/data/test-diff-dwarf/test21-redundant-fn-report-0.txt: Refresh.
	* tests/data/test-diff-dwarf/test27-local-base-diff-report.txt:
	Refresh.
	* tests/data/test-diff-dwarf/test3-report.txt: Refresh.
	* tests/data/test-diff-dwarf/test32-fnptr-changes-report-0.txt:
	Refresh.
	* tests/data/test-diff-dwarf/test33-fnref-changes-report-0.txt:
	Refresh.
	* tests/data/test-diff-dwarf/test36-ppc64-aliases-report-0.txt:
	Refresh.
	* tests/data/test-diff-dwarf/test37-union-report-0.txt: Refresh.
	* tests/data/test-diff-dwarf/test38-union-report-0.txt: Refresh.
	* tests/data/test-diff-dwarf/test39-union-report-0.txt: Refresh.
	* tests/data/test-diff-dwarf/test4-report.txt: Refresh.
	* tests/data/test-diff-dwarf/test40-report-0.txt: Refresh.
	* tests/data/test-diff-dwarf/test44-anon-struct-union-report-0.txt:
	Refresh.
	* tests/data/test-diff-dwarf/test45-anon-dm-change-report-0.txt:
	Refresh.
	* tests/data/test-diff-dwarf/test46-rust-report-0.txt: Refresh.
	* tests/data/test-diff-dwarf/test5-report.txt: Refresh.
	* tests/data/test-diff-dwarf/test8-report.txt: Refresh.
	* tests/data/test-diff-filter/libtest45-basic-type-change-report-0.txt:
	Refresh.
	* tests/data/test-diff-filter/test-PR26739-2-report-0.txt: Refresh.
	* tests/data/test-diff-filter/test0-report.txt: Refresh.
	* tests/data/test-diff-filter/test01-report.txt: Refresh.
	* tests/data/test-diff-filter/test1-report.txt: Refresh.
	* tests/data/test-diff-filter/test10-report.txt: Refresh.
	* tests/data/test-diff-filter/test11-report.txt: Refresh.
	* tests/data/test-diff-filter/test13-report.txt: Refresh.
	* tests/data/test-diff-filter/test14-0-report.txt: Refresh.
	* tests/data/test-diff-filter/test14-1-report.txt: Refresh.
	* tests/data/test-diff-filter/test15-0-report.txt: Refresh.
	* tests/data/test-diff-filter/test15-1-report.txt: Refresh.
	* tests/data/test-diff-filter/test16-report-2.txt: Refresh.
	* tests/data/test-diff-filter/test16-report.txt: Refresh.
	* tests/data/test-diff-filter/test17-0-report.txt: Refresh.
	* tests/data/test-diff-filter/test17-1-report.txt: Refresh.
	* tests/data/test-diff-filter/test18-report.txt: Refresh.
	* tests/data/test-diff-filter/test2-report.txt: Refresh.
	* tests/data/test-diff-filter/test25-cyclic-type-report-0.txt: Refresh.
	* tests/data/test-diff-filter/test25-cyclic-type-report-1.txt: Refresh.
	* tests/data/test-diff-filter/test26-qualified-redundant-node-report-0.txt:
	Refresh.
	* tests/data/test-diff-filter/test26-qualified-redundant-node-report-1.txt:
	Refresh.
	* tests/data/test-diff-filter/test27-redundant-and-filtered-children-nodes-report-0.txt:
	Refresh.
	* tests/data/test-diff-filter/test27-redundant-and-filtered-children-nodes-report-1.txt:
	Refresh.
	* tests/data/test-diff-filter/test27-redundant-and-filtered-children-nodes-report-2.txt:
	Refresh.
	* tests/data/test-diff-filter/test28-redundant-and-filtered-children-nodes-report-0.txt:
	Refresh.
	* tests/data/test-diff-filter/test28-redundant-and-filtered-children-nodes-report-1.txt:
	Refresh.
	* tests/data/test-diff-filter/test29-finer-redundancy-marking-report-0.txt:
	Refresh.
	* tests/data/test-diff-filter/test3-report.txt: Refresh.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
	Refresh.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt:
	Refresh.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt:
	Refresh.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt:
	Refresh.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt:
	Refresh.
	* tests/data/test-diff-filter/test32-ppc64le-struct-change-report0.txt:
	Refresh.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
	Refresh.
	* tests/data/test-diff-filter/test36-report-0.txt: Refresh.
	* tests/data/test-diff-filter/test37-report-0.txt: Refresh.
	* tests/data/test-diff-filter/test39/test39-report-0.txt: Refresh.
	* tests/data/test-diff-filter/test42-leaf-report-output-0.txt: Refresh.
	* tests/data/test-diff-filter/test44-anonymous-data-member-report-0.txt:
	Refresh.
	* tests/data/test-diff-filter/test44-anonymous-data-member-report-1.txt:
	Refresh.
	* tests/data/test-diff-filter/test9-report.txt: Refresh.
	* tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64--2.24.2-30.fc30.x86_64-report-0.txt:
	Refresh.
	* tests/data/test-diff-pkg/PR24690/PR24690-report-0.txt: Refresh.
	* tests/data/test-diff-pkg/dirpkg-1-report-1.txt: Refresh.
	* tests/data/test-diff-pkg/dirpkg-3-report-1.txt: Refresh.
	* tests/data/test-diff-pkg/dirpkg-3-report-2.txt: Refresh.
	* 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:
	Refresh.
	* tests/data/test-diff-pkg/libcdio-0.94-1.fc26.x86_64--libcdio-0.94-2.fc26.x86_64-report.1.txt:
	Refresh.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64--libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64-report-0.txt:
	Refresh.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Refresh.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Refresh.
	* tests/data/test-diff-pkg/symlink-dir-test1-report0.txt: Refresh.
	* tests/data/test-diff-pkg/tarpkg-0-report-0.txt: Refresh.
	* tests/data/test-diff-pkg/tarpkg-1-report-0.txt: Refresh.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
	Refresh.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Refresh.
	* tests/data/test-diff-suppr/libtest48-soname-abixml-report-1.txt:
	Refresh.
	* tests/data/test-diff-suppr/test0-type-suppr-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test0-type-suppr-report-3.txt: Refresh.
	* tests/data/test-diff-suppr/test0-type-suppr-report-5.txt: Refresh.
	* tests/data/test-diff-suppr/test0-type-suppr-report-7.txt: Refresh.
	* tests/data/test-diff-suppr/test1-typedef-suppr-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test1-typedef-suppr-report-2.txt: Refresh.
	* tests/data/test-diff-suppr/test11-add-data-member-report-0.txt:
	Refresh.
	* tests/data/test-diff-suppr/test12-add-data-member-report-0.txt:
	Refresh.
	* tests/data/test-diff-suppr/test12-add-data-member-report-2.txt:
	Refresh.
	* tests/data/test-diff-suppr/test13-suppr-through-pointer-report-0.txt:
	Refresh.
	* tests/data/test-diff-suppr/test13-suppr-through-pointer-report-1.txt:
	Refresh.
	* tests/data/test-diff-suppr/test14-suppr-non-redundant-report-0.txt:
	Refresh.
	* tests/data/test-diff-suppr/test14-suppr-non-redundant-report-1.txt:
	Refresh.
	* tests/data/test-diff-suppr/test15-suppr-added-fn-report-0.txt:
	Refresh.
	* tests/data/test-diff-suppr/test15-suppr-added-fn-report-1.txt:
	Refresh.
	* tests/data/test-diff-suppr/test15-suppr-added-fn-report-5.txt:
	Refresh.
	* tests/data/test-diff-suppr/test16-suppr-removed-fn-report-0.txt:
	Refresh.
	* tests/data/test-diff-suppr/test16-suppr-removed-fn-report-2.txt:
	Refresh.
	* tests/data/test-diff-suppr/test16-suppr-removed-fn-report-5.txt:
	Refresh.
	* tests/data/test-diff-suppr/test17-suppr-added-var-report-0.txt:
	Refresh.
	* tests/data/test-diff-suppr/test17-suppr-added-var-report-2.txt:
	Refresh.
	* tests/data/test-diff-suppr/test17-suppr-added-var-report-5.txt:
	Refresh.
	* tests/data/test-diff-suppr/test18-suppr-removed-var-report-0.txt:
	Refresh.
	* tests/data/test-diff-suppr/test18-suppr-removed-var-report-2.txt:
	Refresh.
	* tests/data/test-diff-suppr/test18-suppr-removed-var-report-5.txt:
	Refresh.
	* tests/data/test-diff-suppr/test2-struct-suppr-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test23-alias-filter-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test23-alias-filter-report-2.txt: Refresh.
	* tests/data/test-diff-suppr/test24-soname-report-1.txt: Refresh.
	* tests/data/test-diff-suppr/test24-soname-report-10.txt: Refresh.
	* tests/data/test-diff-suppr/test24-soname-report-12.txt: Refresh.
	* tests/data/test-diff-suppr/test24-soname-report-14.txt: Refresh.
	* tests/data/test-diff-suppr/test24-soname-report-16.txt: Refresh.
	* tests/data/test-diff-suppr/test24-soname-report-4.txt: Refresh.
	* tests/data/test-diff-suppr/test25-typedef-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test26-loc-suppr-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test26-loc-suppr-report-3.txt: Refresh.
	* tests/data/test-diff-suppr/test29-soname-report-3.txt: Refresh.
	* tests/data/test-diff-suppr/test29-soname-report-6.txt: Refresh.
	* tests/data/test-diff-suppr/test29-soname-report-8.txt: Refresh.
	* tests/data/test-diff-suppr/test3-struct-suppr-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test3-struct-suppr-report-1.txt: Refresh.
	* tests/data/test-diff-suppr/test3-struct-suppr-report-2.txt: Refresh.
	* tests/data/test-diff-suppr/test30-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test31-report-1.txt: Refresh.
	* tests/data/test-diff-suppr/test33-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test35-leaf-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test36-leaf-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test4-local-suppr-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test4-local-suppr-report-1.txt: Refresh.
	* tests/data/test-diff-suppr/test42-negative-suppr-type-report-0.txt:
	Refresh.
	* tests/data/test-diff-suppr/test42-negative-suppr-type-report-1.txt:
	Refresh.
	* tests/data/test-diff-suppr/test46-PR25128-report-1.txt: Refresh.
	* tests/data/test-diff-suppr/test46-PR25128-report-2.txt: Refresh.
	* tests/data/test-diff-suppr/test47-non-reachable-types-report-1.txt:
	Refresh.
	* tests/data/test-diff-suppr/test47-non-reachable-types-report-2.txt:
	Refresh.
	* tests/data/test-diff-suppr/test47-non-reachable-types-report-4.txt:
	Refresh.
	* tests/data/test-diff-suppr/test47-non-reachable-types-report-7.txt:
	Refresh.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-1.txt: Refresh.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-2.txt: Refresh.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-3.txt: Refresh.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-4.txt: Refresh.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-5.txt: Refresh.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-0-1.txt: Refresh.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-1.txt: Refresh.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-2.txt: Refresh.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-3.txt: Refresh.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-4.txt: Refresh.
	* tests/data/test-diff-suppr/test7-var-suppr-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test7-var-suppr-report-1.txt: Refresh.
	* tests/data/test-diff-suppr/test7-var-suppr-report-2.txt: Refresh.
	* tests/data/test-diff-suppr/test7-var-suppr-report-3.txt: Refresh.
	* tests/data/test-diff-suppr/test7-var-suppr-report-4.txt: Refresh.
	* tests/data/test-diff-suppr/test7-var-suppr-report-7.txt: Refresh.
	* tests/data/test-diff-suppr/test7-var-suppr-report-8.txt: Refresh.
	* tests/data/test-diff-suppr/test8-redundant-fn-report-0.txt: Refresh.
	* tests/data/test-diff-suppr/test8-redundant-fn-report-1.txt: Refresh.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2021-02-08 16:29:13 +01:00
Dodji Seketeli
013a19c5fe Bug 27331 - Data member offset change not considered local
The comparison code fails to consider that a data member which offset
changed (and which type didn't change) constitutes a local change of
the enclosing class type.

Fixed thus.

	* src/abg-ir.cc (equals): In the overload of class_or_union, when
	a data member changes without having its type change, then
	consider the data change as being local.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt:
	Adjust.
	* tests/data/test-diff-filter/test-PR27331-report-0.txt: New
	reference output.
	* tests/data/test-diff-filter/test-PR27331-v{0,1}.c: New test
	source files.
	* tests/data/test-diff-filter/test-PR27331-v{0,1}.o: New test
	binary inputs.
	* tests/data/Makefile.am: Add these new test material to source
	distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the tests above to
	the harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-02-03 13:55:38 +01:00
Dodji Seketeli
6ef9dafdd9 Bug 26684 - Support DW_AT_data_bit_offset attribute
This patch adds support for the DW_AT_data_bit_offset DWARF 5
attribute.  Note that this attribute has been introduced in prior
versions of DWARF, but since the version 5, it supersedes the
DW_AT_bit_offset attribute.

Note that Libabigail was wrongly interpreting the DW_AT_bit_offset
attribute.  It was considering it as the offset of the bit field data
member, starting from the least significant bit of the containing
structure.  That is not the case on little endian machines,
unfortunately.

So this patch fixes that mistake.

So with this patch, we can now compare a binary using DW_AT_bit_offset
against a binary using DW_AT_data_bit_offset and expect things to work
correctly.

The problem is that abixml files generated with Libabigail versions
prior to this patch contain bit field data member offset values that
are not compatible with those contained in abixml files generated with
this version, onward.

So I guess a subsequent patch is needed to introduce a new abixml
version string (maybe "2.0") that would be deemed incompatible with
the previous "1.0" one.  That way, we can prevent comparing 2.0 abixml
files against 1.0 ones in abidiff, for instance.

For now, the patch adjusts the various abixml files to make them
reflect the proper representation of DW_AT_bit_offset on little endian
machines.

	* src/abg-dwarf-reader.cc (read_and_convert_DW_at_bit_offset):
	Define new static function.
	(die_member_offset): Primarily use DW_AT_data_bit_offset if its
	present.  Otherwise, look for DW_AT_bit_offset.  Use the new
	read_and_convert_DW_at_bit_offset function to properly interpret
	DW_AT_bit_offset if its present.  Update comment.
	* tests/data/test-diff-filter/test-PR26684-dwarf{4,5}.o: New
	binary test inputs.
	* tests/data/test-diff-filter/test-PR26684.c: Source code of the
	new binary test inputs above.
	* tests/data/test-diff-filter/test-PR26684-report-0.txt: New
	reference test output.
	* tests/data/Makefile.am: Add the new test material above to
	source distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the test inputs
	above to this test harness.
	* tests/data/test-annotate/test13-pr18894.so.abi: Adjust.
	* tests/data/test-annotate/test15-pr18892.so.abi: Adjust.
	* tests/data/test-annotate/test17-pr19027.so.abi: Adjust.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Adjust.
	* tests/data/test-annotate/test21-pr19092.so.abi: Adjust.
	* tests/data/test-diff-dwarf-abixml/PR25409-librte_bus_dpaa.so.20.0.abi:
	Adjust.
	* tests/data/test-diff-pkg/libcdio-0.94-1.fc26.x86_64--libcdio-0.94-2.fc26.x86_64-report.1.txt:
	Adjust.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Adjust.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Adjust.
	* tests/data/test-read-dwarf/test13-pr18894.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/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Adjust.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Adjust.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-01-29 18:28:25 +01:00
Dodji Seketeli
4dab7cd970 dwarf-reader: Support fast DW_FORM_line_strp string comparison
When running Libabigail on Fedora 34 it appeared that we don't support
DW_FORM_line_strp in the fast string comparison scheme, during DIE
de-duplication.

This patch fixes that.

	* src/abg-dwarf-reader.cc (compare_dies_string_attribute_value):
	Support DW_FORM_line_strp.
	* tests/data/test-diff-pkg/sshpass-1.07-1.fc34.x86_64-self-check-report-0.txt:
	New reference test output.
	* tests/data/test-diff-pkg/sshpass-1.07-1.fc34.x86_64.rpm: New
	test input.
	* tests/data/test-diff-pkg/sshpass-debuginfo-1.07-1.fc34.x86_64.rpm:
	Likewise.
	* tests/data/Makefile.am: Add the new testing material above to
	source distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the test input above
	to this harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-01-26 19:19:01 +01:00
Dodji Seketeli
40709acdd5 Bug 27232 - fedabipkgdiff fails on gawk from Fedora 33
When running fedabipkgdiff on the gawk-5.1.0-2.fc33.aarch64.rpm
package we get this error message:

    Error encountered while running fedabipkgdiff with error message:

That is not a very useful error message to say the least.

The issue is that abipkgdiff returns with an "unknown error" which is
due to the fact that the gawk package contains a directory that is
owned by root.  As abipkgdiff tries to write temporary files into that
directory, it fails to do so.

The patch now writes the temporary ABIXML file into a sub-directory
that is not owned the package where we should have write privileges.

It also improves error reporting.

	* tools/abipkgdiff.cc (options::pkg{1,2}): Add new data members to
	store the packages to compare and have them available for the
	various functions that may need them down the road.
	(package::create_abi_file_path): Add new function.
	(compare_to_self): Use the new package::create_abi_file_path to
	create the path to the ABI file in a directory not owned by the
	package.  That should increase our chances of having the rights to
	write that one.  Make sure to emit error message when the
	comparison against self fails.
	({compare_task, self_compare_task}::perform): During the process
	of comparison if an internal error happens, report it.  Cleanup
	the existing reporting a little bit.
	(pkg_extraction_task::perform): Fix comment.
	* tests/data/test-diff-pkg/libxfce4ui-devel-4.12.1-8.fc27.ppc64-self-report-0.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-01-26 17:41:33 +01:00
Dodji Seketeli
e9bcf8634f Bug 27236 - Pointer comparison wrongly fails because of typedef change
Support we have a type struct S and a type T defined as:
  typedef struct S T;

Today, Libabigail considers that the two pointers "struct S*" and "T*"
are different.

The problem is that this can cause spurious change reports (as
reported by (abidw --abidiff) in binaries where we have the same type
defined more than once, each time using a different various around
this theme.

This patch make libabigail to now consider that "struct S*" and "T*"
are equal.  It does the same for references and arrays.

	 * src/abg-ir.cc (equals): In the overloads for pointer_type_def,
	reference_type_def and array_type_def, compare the pointed-to-type
	modulo typedefs.
	* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt: Adjust.
	* tests/data/test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm--libICE-1.0.9-2.el7.x86_64.rpm-report-0.txt:
	Adjust.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-01-26 04:48:20 +01:00
Dodji Seketeli
9a0c823df4 Ignore duplicated functions and those not associated with ELF symbols
While looking at several ABIXML files I noticed that several (member)
functions didn't have any associated ELF symbol and that in some cases,
there were even duplicated member functions.  Those are the source of
some spurious changes sometimes reported by abidiff.

In DWARF the same function F can be represented several times.  One
representation of F has some properties and other representations of F
might have properties that complement the properties carried by the
former representations.  It's the unions of the properties of all
representations of F that constitute the properties of F.

An example of that "linked" nature is how DWARF represents inlined
functions.  A function F can be inlined somewhere else.  That inlined
version is called F', for instance.  The DWARF representation of F'
will carry a DW_AT_abstract_origin attribute that points back to F to
signify that F' is the concrete inlined version of the abstract F.

F' will carry properties that are specific to its "inlined nature"
whereas F will carry properties that are more generic and independent
from all its various potential inlined forms.

So when Libabigail sees the DWARF representation of F, if it's
associated with an ELF symbol, then it must wait to encounter an F'
representation that is associated with an ELF symbol before adding an
internal representation (IR) of F into the final IR graph.  Otherwise
the IR of F can be unnecessarily duplicated, with some instances
having an associated ELF symbol and others not.

This is what this patch does, in essence.  While working on this, I
encountered some tangential issues that needed to be fixed altogether
for the whole to function.  A lot of regression tests output had to be
adjusted.

In the end, a number of spurious change reports could be fixed;
notably reports about removal of destructors like STR::~STR(int).
Note how that destructor has a parameter; it's a GCC-specific
implementation detail that should not appear at this level, I believe.

	* include/abg-ir.h (class_or_union::string_mem_fn_sptr_map_type):
	Add a typedef for unordered_map<string, method_decl_sptr>.
	(class_or_union::find_member_function_sptr): Declare new function.
	* src/abg-ir.cc (class_or_union::priv::mem_fns_map_): Change the
	type of this to string_mem_fn_sptr_map_type, so that shared
	pointers to functions can be stored in the map, instead of bare
	pointers to functions.  This is useful to implement
	class_or_union::find_member_function_sptr which returns a shared
	pointer to function.
	(class_or_union::find_member_function_sptr): Define new function.
	(class_or_union::find_member_function): Adjust.
	(method_decl::set_linkage_name): Use a non-deleting shared pointer
	to store the current instance of member function into
	class_or_union::priv::mem_fns_map_.
	(hash_as_canonical_type_or_constant): As we are seeing more
	function types, it appears that some function types are not
	canonicalized.  I am not sure why exactly, but let's loosen the
	assert here for now, I'll chase the root of this later.
	* src/abg-dwarf-reader.cc (finish_member_function_reading):
	Improve detection of member function 'static-ness' by handling
	cases where a this pointer can be const.  Also support
	DW_AT_object_pointer when it's present.  This fixes the occurrence
	of spurious change reports about loss of 'static-ness' of member
	functions.
	(potential_member_fn_should_be_dropped): Define new static
	function and ...
	(build_ir_node_from_die): ... use it here.  When a function DIE
	has the same linkage name as an existing function IR, do not
	create a new IR for it.  Rather, re-use the existing one to
	complete it with the properties found on the function DIE.  If a
	new function doesn't seem to have an associated ELF symbol and is
	not meant to be a virtual member function then drop its IR on the
	floor as well.
	* tests/data/test-annotate/libtest23.so.abi: Adjust.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test0.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-annotate/test6.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi: Likewise.
	* tests/data/test-diff-dwarf-abixml/PR25409-librte_bus_dpaa.so.20.0.abi: Likewise.
	* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi: Likewise.
	* tests/data/test-diff-dwarf/test0-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test28-vtable-changes-report-0.txt: Likewise.
	* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt: Likewise.
	* tests/data/test-diff-filter/test0-report.txt: Likewise.
	* tests/data/test-diff-filter/test01-report.txt: Likewise.
	* tests/data/test-diff-filter/test10-report.txt: 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/test30-pr18904-rvalueref-report2.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test9-report.txt: Likewise.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64--libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-10.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-12.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-14.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-16.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-4.txt: Likewise.
	* tests/data/test-diff-suppr/test31-report-1.txt: Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test0.abi: Likewise.
	* tests/data/test-read-dwarf/test0.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test1.hash.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/test14-pr18893.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Likewise.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise.
	* tests/data/test-read-dwarf/test6.so.abi: Likewise.
	* tests/data/test-read-dwarf/test6.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.abi: Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-01-23 16:36:15 +01:00
Dodji Seketeli
1dcdd54d54 Bug 27204 - potential loss of some aliased ELF function symbols
Sometimes when a symbol S' of a function F' aliases the symbol S of a function
F, the ABIXML reader might not add F' back into the set of exported
functions of the ABI corpus (as the DWARF reader has done initially).
That results in the apparent 'loss' of F' (and S') from the corpus.

This is due to the way F' is identified, using function_decl::get_id.
In the case where the symbol S' of F' has aliases,
function_decl::get_id (wrongly) uses the linkage name of F' as the
identifier.  If F' and F happen to have the same linkage name and if F
is already in the set of exported functions of the corpus then F'
won't be added into that set.

To solve that problem, this patch makes function_decl::get_id
construct an ID that ensures that F and F' always have different IDs.

	* src/abg-ir.cc (function_decl::get_id): If the elf symbol has
	aliases, make the function name be part of the ID so that this ID
	differs from the one of the other functions that share a symbol
	alias with this one.
	* tests/data/test-abidiff/test-PR18791-report0.txt: Adjust.
	* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-diff-pkg/glibc-2.32-3.fc33.aarch64-self-check-report-0.txt:
	New test reference output.
	* tests/data/test-diff-pkg/glibc-2.32-3.fc33.aarch64.rpm: New test
	input RPM.
	* tests/data/test-diff-pkg/glibc-debuginfo-2.32-3.fc33.aarch64.rpm:
	Likewise.
	* tests/data/Makefile.am: Add the new test material to source
	distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the new test input
	RPMs to this test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-01-23 16:35:11 +01:00
Dodji Seketeli
625d0903c2 Bug 26992 - Try harder to resolve declaration-only classes
When a declaration of a class, named H, matches more than one
definition (let's call them D) of H (in several other translation
units of the abi corpus) then H is left unresolved; that is, H is
considered as being a declaration-only class.  Note that down the
road, H will compare different to all those Ds.

However when those Ds are all equal, it turns out that this can lead
to issues down the road.  This is because conceptually, H equals D.
But then by not resolving H to D (and there are several Ds), we
artificially create a situation where H is different from D.  We can
even create situations where those Ds are different among themselves.
So doing comparisons inevitably leads to spurious changes.

This is the root cause of the issue described in this bug at
https://sourceware.org/bugzilla/show_bug.cgi?id=26992.

To fix the issue, this patch thus resolves H to D when the different
Ds are all equal.

Note that a similar thing should be done for the process of resolving
declaration-only enums as well.  But I don't have an issue reproducer
at hand involving enums at the moment, so I am adding a comment to
read_context::resolve_declaration_only_enums for now.

I have also filled the enhancement request
https://sourceware.org/bugzilla/show_bug.cgi?id=27189 to track a task
that would do away with read_context::resolve_declaration_only_enums
altogether by factorizing out the resolution of declaration-only
abigail::ir::decl_base.

	* src/abg-dwarf-reader.cc
	(read_context::compare_before_canonicalisation): Define new member
	function.
	(read_context::resolve_declaration_only_classes): When there are
	more than one definition that can resolve a given declaration, if
	all those definitions are equal, then resolve the declaration to
	those definitions.
	(read_context::resolve_declaration_only_enums): Add a comment to
	update similarly update this function (or do away with it
	completely) later.
	* tests/data/test-annotate/test15-pr18892.so.abi: Adjust.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-diff-pkg/cogl-1.22.8-2.fc33.x86_64.rpm: Add new
	test input.
	* tests/data/test-diff-pkg/cogl-debuginfo-1.22.8-2.fc33.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/cogl-1.22.8-2.fc33.x86_64.self-check-report-0.txt:
	Likewise.
	* tests/test-diff-pkg.cc (in_out_specs): Add the new test inputs
	to the test harness.
	* tests/data/Makefile.am: Add the new test input files to source
	distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-01-15 18:01:56 +01:00
Dodji Seketeli
b553802af8 Bug 26780 - Fix array subrange bounds (de)serialization
When serializing subrange bounds to ABIXML today the writer omits the
lower and upper bounds.  Only the length is emitted.  The reader thus
assumes that the lower bound of an array subrange is always 0.  In
Fortran however, that is not true, as the lower bound is 1.

This patch instructs the writer to emits the lower bound whenever it's
different from zero.  It also emits the upper bound in that case.  The
reader is updated accordingly to take the lower and upper bounds into
account whenever they are present.  It they are not, then the
lower bound is assumed to be zero and the upper bound is deduced from
the length, as was already the case until now.

	* src/abg-reader.cc (build_subrange_type): Read lower-bound
	attribute if present.  Then try to read upper-bound attribute as
	well.  If this is not an infinite subrange assert that the length
	must be equal to the difference between the bounds.
	* src/abg-writer.cc (write_array_subrange_type): Write the
	lower-bound if it's present and not zero.  In that case, write the
	upper-bound as well.
	* tests/data/test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.rpm: Add new
	binary test input.
	* tests/data/test-diff-pkg/hdf5-debuginfo-1.10.6-2.fc33.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.self-check-report-0.txt:
	Add new reference output.
	* tests/data/Makefile.am: Add the new test material above to
	source distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the binary test input
	to the set of --self-check tests.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-11-27 13:50:47 +01:00
Dodji Seketeli
c2ce1a38c6 dwarf-reader: support artificially generated translation units
When GCC 10 artificially generates a translation unit, the path/name
of the translation unit as given by the DW_AT_name attribute of the
translation unit DIE is the string "<artificial>".

Libabigail expects that translation units have unique file paths so
having several artificially generated translation units like this one
with the same name makes hell break loose down the road.

This patch suffixes the name of artificial DIE with their die offset
number to have a unique path name for artificially generated
translation units.

	* configure.ac: Detect if we are running on RPM >= 4.15.  If yes,
	then define the preprocessor macro RPM_4_15.  If that macro is
	defined then test-diff-pkg.cc can support RPMs from Fedora >= 31
	as those are compressed with zstd.  Earlier RPM versions don't
	support that compression scheme.
	* src/abg-dwarf-reader.cc (build_translation_unit_and_add_to_ir):
	Suffix the offset of the translation unit to its name when that
	name is "<artificial>".
	* tests/data/test-diff-pkg/mesa-libGLU-9.0.1-3.fc33.x86_64.rpm:
	New binary test input.
	* tests/data/test-diff-pkg/mesa-libGLU-debuginfo-9.0.1-3.fc33.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/mesa-libGLU-9.0.1-3.fc33.x86_64.self-check-report-0.txt:
	New reference output for the binary test input above.
	* tests/data/Makefile.am: Add the new test inputs above to source
	distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the binary test
	inputs above to source distribution if we are running on an RPM
	version >= 4.15.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-11-24 05:04:06 +01:00