Commit Graph

2815 Commits

Author SHA1 Message Date
Dodji Seketeli
e17e107635 big-tests: Update to commit bd0c1f8909a7b2f5018d54b82f7d6829c4849b59
* big-tests: Update to latest commit bcec65b53b8332710f8d74adf4d6a060a91ab5ee

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-09-15 14:57:08 +02:00
Dodji Seketeli
0a6f55aabc ir: Use definition of decl-only parm type in function type names
When the type of a function parameter is a declaration-only type and
if it has a definition, then this patch uses that definition in the
representation of the function type name.

Note that the ABIXML writer always emits definitions of
declaration-only types when they are available so if we don't use
those definitions in the function type representations, there might be
subtle self-comparison errors down the road.

This patch fixes the self-comparison of the OpenMolcas package in
Fedora 36 which was failing for the command:

    $ fedabipkgdiff --self-compare -a --from fc36 OpenMolcas

	* src/abg-ir.cc (stream_pretty_representation_of_fn_parms): Use
	the definition of decl-only function parameter types in the
	representation.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-09-07 00:47:00 +02:00
Dodji Seketeli
c29f0f2679 corpus: Allow several variables with same ID to be exported
The libQt6Network.so.6.3.1 exhibits some interesting debug info where
two variables with slightly different qualified name have the same ELF
symbol.

Consider the DIE for this variable:
 [ 1aab3]    variable             abbrev: 118
             name                 (GNU_strp_alt) "backendMutex"
             decl_file            (implicit_const) qsslsocket_p.h (42)
             decl_line            (data1) 196
             decl_column          (data1) 26
             linkage_name         (GNU_strp_alt) "_ZN17QSslSocketPrivate12backendMutexE"
             type                 (ref_udata) [ 1aa35]
             external             (flag_present) yes
             declaration          (flag_present) yes
             inline               (implicit_const) declared_inlined (3)
             location             (exprloc)
              [ 0] addr +0x1e3050 <_ZN17QSslSocketPrivate12backendMutexE>

This DIE designates a variable named backendMutex in the global
namespace.  It's associated to the ELF symbol
_ZN17QSslSocketPrivate12backendMutexE.

Then, later, there is this DIE:

 [d05d3e]    class_type           abbrev: 260
             name                 (GNU_strp_alt) "QSslSocketPrivate"
             declaration          (flag_present) yes
             sibling              (ref_udata) [d05d70]
[...]
 [d05d70]    variable             abbrev: 642
             name                 (GNU_strp_alt) "backendMutex"
             decl_file            (implicit_const) qsslsocket_p.h (54)
             decl_line            (data1) 196
             decl_column          (data1) 26
             linkage_name         (GNU_strp_alt) "_ZN17QSslSocketPrivate12backendMutexE"
             type                 (ref_addr) [  fdc5]
             external             (flag_present) yes
             declaration          (flag_present) yes
             inline               (implicit_const) declared_inlined (3)
             location             (exprloc)
              [ 0] addr +0x1e3050 <_ZN17QSslSocketPrivate12backendMutexE>

Here, this DIE represents a static data member named
QSslSocketPrivate::backendMutex, as it's member of the
QSslSocketPrivate class.  Note how it's also associated with the ELF
symbol _ZN17QSslSocketPrivate12backendMutexE.

So both variables are associated with the same ELF symbol and should
thus be exported from the ABI corpus.

Today, only one of these variables is represented as exported in the
corpus.  Depending on the order in which the variables are analyzed,
the variable that is represented as exported might be either one or
the other, leading to some spurious self-comparison errors.

This patch fixes the issue by allowing the corpus to represent more
than one variable having a given ELF symbol to be exported.  This is
similar to what is already for functions.

This fixes the self comparison of the qt6-qtbase package, which can be
witnessed by issuing the command:

    $ fedabipkgdiff --self-compare -a --from fc36 qt6-qtbase

	* include/abg-corpus.h (corpus::lookup_variables): Replace
	corpus::lookup_variable with this one which returns the set of
	variables associated with a given ID of variable.
	* src/abg-corpus-priv.h (istr_var_ptr_set_map_type): Define new
	typedef.
	(corpus::exported_decls_builder::priv::id_vars_map_): Replace
	id_var_map_ with this new data member of type
	istr_var_ptr_set_map_type.
	(corpus::exported_decls_builder::priv::id_fns_map): Fix comment.
	(corpus::exported_decls_builder::priv::id_vars_map): Replace
	previous id_var_map with this member function.
	(corpus::exported_decls_builder::priv::var_id_is_in_id_vars_map):
	Replace the var_id_is_in_id_var_map member function.
	(corpus::exported_decls_builder::priv::var_is_in_vars): Define new
	static member function.
	(corpus::exported_decls_builder::priv::{var_is_in_id_vars_map, add_var_to_id_vars_map}):
	Define new member functions.
	(corpus::exported_decls_builder::priv::add_var_to_map): Remove.
	(corpus::exported_decls_builder::priv::add_var_to_exported):
	Adjust by using the new var_is_in_id_vars_map and
	add_var_to_id_vars_map.
	* src/abg-corpus.cc
	(corpus::exported_decls_builder::maybe_add_var_to_exported_vars):
	Adjust, use the new
	corpus::exported_decls_builder::priv::var_is_in_id_vars_map.
	(corpus::lookup_variables): Replace corpus::lookup_variable with
	this one which returns the set of variables associated with a
	given ID of variable.
	* tools/abicompat.cc
	(compare_expected_against_provided_variables): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-09-06 22:35:22 +02:00
Dodji Seketeli
bf3095b1f3 ABIXML reader: Unconditionally map a pointer XML node to its decl
While looking at something else, I noticed that in some rare cases we
might omit to map the XML node representing a pointer to its decl.

	* src/abg-reader.cc (build_pointer_type_def): Unconditionally map
	a pointer type XML node to its decl.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-09-06 15:30:11 +02:00
Dodji Seketeli
83f611b5f7 ir: Improve the checks done by 'abidw --debug-tc'
The abidw --debug-tc option (enabled by the
--enable-debug-type-canonicalization configure option) performs every
type comparison twice; once structurally and once canonically.

This patch improves that checking mode by disabling comparison result
caching.  It makes things slower but it makes the checking more
reliable.

	* src/abg-ir.cc (compare_types_during_canonicalization): Disable
	type comparison result caching during type canonicalization
	debugging.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-09-06 15:30:00 +02:00
Dodji Seketeli
4cea6708d6 ir: Strip typedefs from pointed-to-types during comparison
When comparing two pointers, a pointer to type T is considered
different from a pointer to typedef-of-T.  This can lead to spurious
self-comparison errors and doesn't provide any practical benefit.
More-over, the hash value of type typedef-of-T is the same as the hash
value of type T.  So today, a pointer to type T and pointer to
typedef-of-T have the same hash value.

This patch strips typedefs from the pointed-to type of pointers and
references before comparing them.  It thus fixes the self-comparison
issue exhibited by the command:

    $ fedabipkgdiff --self-compare -a --from fc36 binutils

	* src/abg-ir.cc (equals): In the overload for pointers and
	reference types, strip typedefs off of pointed-to types before
	comparing them.
	* 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/test21-pr19092.so.abi: 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/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/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/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-09-05 17:56:24 +02:00
Dodji Seketeli
3dae26e28c hash,reader,writer: (De)Serialize hash values using the xxhash canonical form
The XH64 hashing function expects an array of bytes as the input data
to hash.  Depending on the machine's endian-ness, an 8 bytes integer
passed to XH64 might be represented differently, leading to different
hash values depending on the endian-ness.  Also, once the hash value
is computed, we need to serialize it and store it as a string of
characters in the ABIXML format.  That too represents potential
avenues for getting the endian-ness wrong.

This patch standardizes the representation of data to be given to XH64
using the big endian representation.  The xxhash project itself uses
the big endian representation as its canonical form using the data
type XXH64_canonical_t.  Almost all the ABIXML files of the test-suite
had to be updated.  This should fix the regressions we are seeing on
big endian machines since the type hashing patch landed in the
mainline.

	* include/abg-hash.h (deserialize_hash, serialize_hash): Declare
	new functions.
	* src/abg-hash.cc (deserialize_hash, serialize_hash): Define them.
	(char_to_int, int_to_char): Define static functions.
	(hash): For the overload that hashes an integer, make it take a
	second one as hashing seed.  Also, lay out the integer value to
	hash in big endian format before passing it to XH64.
	(combine_hashes): Use the amended hash function above.
	* src/abg-reader.cc (read_type_hash_and_cti): Use the new
	deserialize_hash function.
	* src/abg-writer.cc (write_type_hash_and_cti): Use the new
	serialize_hash function.
	* tests/data/test-annotate/PR29443-missing-xx.o.annotated.abi:
	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/test-pointer-to-member-1.o.annotated.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-annotate/test3.so.abi: Likewise.
	* tests/data/test-annotate/test4.so.abi: Likewise.
	* tests/data/test-annotate/test5.o.abi: Likewise.
	* tests/data/test-annotate/test6.so.abi: Likewise.
	* tests/data/test-annotate/test7.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi:
	Likewise.
	* tests/data/test-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-read-btf/test0.o.abi: Likewise.
	* tests/data/test-read-btf/test1.o.abi: Likewise.
	* tests/data/test-read-ctf/PR27700/test-PR27700.abi: Likewise.
	* tests/data/test-read-ctf/test-PR26568-1.o.abi: Likewise.
	* tests/data/test-read-ctf/test-PR26568-2.o.abi: Likewise.
	* tests/data/test-read-ctf/test-alias.o.abi: Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-A.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-B.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-anonymous-fields.o.abi: Likewise.
	* tests/data/test-read-ctf/test-array-mdimension.abi: Likewise.
	* tests/data/test-read-ctf/test-array-of-pointers.abi: Likewise.
	* tests/data/test-read-ctf/test-array-size.abi: Likewise.
	* tests/data/test-read-ctf/test-bitfield-enum.abi: Likewise.
	* tests/data/test-read-ctf/test-bitfield.abi: Likewise.
	* tests/data/test-read-ctf/test-callback.abi: Likewise.
	* tests/data/test-read-ctf/test-callback2.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-const-array.abi: Likewise.
	* tests/data/test-read-ctf/test-dynamic-array.o.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-many.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-symbol.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-enum.o.abi: Likewise.
	* tests/data/test-read-ctf/test-fallback.abi: Likewise.
	* tests/data/test-read-ctf/test-forward-type-decl.abi: Likewise.
	* tests/data/test-read-ctf/test-functions-declaration.abi:
	Likewise.
	* tests/data/test-read-ctf/test-linux-module.abi: Likewise.
	* tests/data/test-read-ctf/test-list-struct.abi: Likewise.
	* tests/data/test-read-ctf/test0.abi: Likewise.
	* tests/data/test-read-ctf/test0.hash.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/test3.so.abi: Likewise.
	* tests/data/test-read-ctf/test3.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test4.so.abi: Likewise.
	* tests/data/test-read-ctf/test4.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-ctf/test8.o.abi: Likewise.
	* tests/data/test-read-ctf/test9.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/PR28584/PR28584-smv.clang.o.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR29443-missing-xx.o.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-fallback.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-pointer-to-member-1.o.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/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/test15.xml: Likewise.
	* tests/data/test-read-write/test18.xml: Likewise.
	* tests/data/test-read-write/test21.xml: Likewise.
	* tests/data/test-read-write/test24.xml: Likewise.
	* tests/data/test-read-write/test25.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>
2024-09-03 15:36:40 +02:00
Dodji Seketeli
2d858753d1 comparison: Sort anonymous types using their flat representation
When changes to types non-reachable from external interfaces are
emitted, they are sorted using the pretty representation of said
types.  In the current form, it's the "internal" pretty representation
that is used for the sorting.  That internal form, which is normally
used for the purpose of type canonicalization, doesn't differentiate
an anonymous types against another one.  For instance, all anonymous
enums are named __anonymous_enum__.  In that case, the sorting of
anonymous type changes becomes non stable.

This patch uses the non-internal form of type pretty representation
for the sorting.  In that form, anonymous enums are named using their
flat representation.

	* src/abg-comparison-priv.h (diff_comp::operator()): Use the
	non-internal pretty representation for sorting.
	* tests/data/test-abidiff-exit/test-anon-types-report-1.txt:
	Adjust.
	* tests/data/test-abidiff-exit/test-anonymous-enums-change-report-v1.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-09-02 10:06:22 +02:00
Claudiu Zissulescu
2e0e67d920 abg-tools-utils: Fix memory corruption when using CTF option
The scope of di_root_ctf_ptr is limited to the if-block it's defined
in, yet its address is passed to create_best_elf_based_reader, outside
that block.  So that address becomes invalid for the code of
create_best_elf_based_reader.  Fixed thus.

	* src/abg-tools-utils.cc
	(build_corpus_group_from_kernel_dist_under): change the scope of
	di_root_ctf_ptr variable.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-30 17:41:25 +02:00
Dodji Seketeli
b6add20f05 dwarf-reader,ir,writer: Better support for static member variables
To support the duality concrete/abstract instance of static data
member variables in DWARF, the reader needed a little bit of an
overhaul.  That overhaul is necessary to self-compare libLLVM.so, from
llvm-libs, in fc37.  Note that that self-compare is done using this
command:

    $ fedabipkgdiff -a--self-compare --from fc37 llvm-libs

So now, with this patch, the IR of a static data member is constructed
only when the concrete instance DIE of the static data member is
encountered.  The abstract instance DIE is then read first, the IR is
built from it, and then the concrete instance DIE is read for
additional attributes that might be needed, like the ELF symbol
attribute.

The patch fixes a number of issues related to static data members
representation in the IR, namely, it puts them all in their own array
in the class_or_union, just like what is done for non-static data
members.  The ABIXML writer is updated to emit static data member from
their new storage.

	* include/abg-ir.h (class_or_union::get_static_data_members):
	Declare new method.
	* src/abg-dwarf-reader.cc (add_or_update_class_type): Do not
	create any IR for the /declaration/ of static data member here.
	Wait for its definition from a concrete instance DIE to create the
	IR for it.
	(build_ir_node_from_die): In the DW_TAG_variable case, if we are
	looking at the concrete instance of a static variable (one that
	has a DW_AT_abstract_origin pointing to a static data member) then
	build the IR from it and add it to its class scope.
	* src/abg-ir-priv.h (class_or_union::priv::static_data_members_):
	Define new data member.
	(class_or_union::priv::priv): Stick the static data members that
	are in class_or_union::priv::data_members_ into
	class_or_union::priv::static_data_members_.
	* src/abg-ir.cc (maybe_adjust_canonical_type): Make sure static
	data members of the canonical type has the same symbols set as the
	data members of the canonicalized type.
	(class_or_union::add_data_member): Update the new
	class_or_union::priv::static_data_members_ when a data member is
	added.
	(class_or_union::get_non_static_data_members): Fix comments.
	(class_or_union::get_static_data_members): Define new member
	functions.
	(set_member_is_static): Update the new
	class_or_union::priv::static_data_members_ when static-ness is
	changed.
	* src/abg-writer.cc (write_decl_in_scope): Support writing pure
	declarations (not types).
	(write_translation_unit): Don't forget to write remaining global
	variables.
	(write_class_decl): Make sure to write static data members first,
	before writing the non-static data members.
	* tests/data/test-abidiff-exit/test-ld-2.28-210.so--ld-2.28-211.so.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/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-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-filter/test30-pr18904-rvalueref-report1.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.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/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/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/test10.xml: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
ce31d8ad5d dwarf-reader,reader.cc: Fix function virtuality setting
When setting the virtual-ness of a function (whether it's virtual or
not and its vtable offset), one must set the vtable offset before
setting the is_virtual property because setting the later triggers a
fix-up that uses the former.

It turns out some parts of the code got the order wrong.  To fix that,
this patch introduce a new set_member_function_virtuality that ensures
things are done in the proper order.

SET_member_function_vtable_offset and set_member_function_is_virtual
are now static functions that are used only by the new
set_member_function_virtuality.

	* include/abg-fwd.h (set_member_function_vtable_offset)
	(set_member_function_is_virtual): Remove these function
	declarations.
	(set_member_function_virtuality): Declare new function.
	* include/abg-ir.h (decl_base::get_context_rel): Make this public.
	(set_member_function_is_virtual)
	(set_member_function_vtable_offset): Remove these friend
	declaration for the decl_base class.
	* src/abg-dwarf-reader.cc (finish_member_function_reading): Use
	the new set_member_function_virtuality in lieu of the previous
	set_member_function_is_virtual and
	set_member_function_vtable_offset.
	* src/abg-ir.cc (set_member_function_vtable_offset)
	(set_member_function_is_virtual): Make these functions static.
	(set_member_function_virtuality): Define new functions.
	(class_or_union::add_member_function): Use the new
	set_member_function_virtuality in lieu of
	set_member_function_is_virtual and
	set_member_function_vtable_offset.
	* src/abg-reader.cc (build_class_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
5be5809f7c abipkgdiff: Extract devel and main packages in the same directory
abipkgdiff extracts the two devel packages in directories named
"devel_package{1,2}, whereas the main packages are extracted in
directories named package{1,2}.  This is wrong because a devel package
should be extracted into the same directory tree as the main package.
For instance, there can be a foo.so symbolic link (coming from the
devel package) that points to the foo-1.0.0.so (coming from the main
package) below usr/lib64/ in the extracted directory.  If the devel
and main packages are extracted in different directories then the
symbolic link is going to be broken and some binaries won't be
ABI-compared.

This patch fixes the issue by extracting devel packages into the same
directory as the main one.  Then, it makes sure the devel package and
the main one are extracted sequentially, not in parallel since they
are not being extracted into the same directory.

By fixing this, a number of previously hidden issues or even change
output are now exposed.  The patch updates these.

	* tests/data/test-diff-pkg/gcc-debuginfo-14.2.1-1.fc40.x86_64.rpm:
	Add missing debug info package.
	* tests/data/Makefile.am: Add it to source distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the debuginfo package
	to the libgm2 test.
	* tools/abipkgdiff.cc (main): Extract the devel packages into the
	"package1" and "package2" directories.
	(extract_package_and_map_its_content): Extract the main and devel
	packages sequentially, not in parallel.
	(self_compare_prepared_userspace_package): Add more logs.
	* tests/data/test-fedabipkgdiff/test0-from-fc20-to-fc23-dbus-glib-report-0.txt:
	Adjust.
	* tests/data/test-fedabipkgdiff/test1-from-fc20-to-dbus-glib-0.106-1.fc23.x86_64-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/test4-glib-0.100.2-2.fc20.x86_64.rpm-glib-0.106-1.fc23.x86_64.rpm-report-0.txt:
	Likewise
	* tests/data/test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-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

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
00d8507648 dwarf-reader,ir: Fix endless loop while analyzing DWARF from Modula-2
While reading the DWARF of libm2iso.so.19.0.0 from the package
libgm2-14.2.1-1.fc40.x86_64.rpm (Modula-2 library for the gcc-gm2
package), abidw crashes due to a stack overflow, because of an endless
loop while trying to print the type names for DIEs in the DWARF
reader.

This is due to this kind of recursive construct of an anonymous type
at offset 0xf1:

 [    f1]    structure_type       abbrev: 30
             byte_size            (data1) 32
             decl_file            (data1) RTentity.mod (12)
             decl_line            (data1) 34
             decl_column          (data1) 23
             sibling              (ref_udata) [   126]
 [    f7]      member               abbrev: 64
               name                 (GNU_strp_alt) "left"
               decl_file            (data1) RTentity.mod (12)
               decl_line            (data1) 35
               decl_column          (data1) 26
               type                 (ref_udata) [   126]
               data_member_location (data1) 0
[...]

Consider the data member name "left" at offset 0xf7.  The offset of
it's type DIE is 0x126.

Here is the DIE at offset 0x126:

 [   126]    pointer_type         abbrev: 48
             byte_size            (implicit_const) 8
             type                 (ref_udata) [    f1]

It's a pointer to a type described by the DIE at offset ... 0xf1.
That is a cycle in the graph of that anonymous type, right there.

To name an anonymous struct like this, the DWARF reader constructs its
"flat representation".  Namely, the idea is to represent the struct by
a string that looks like:

    "struct {type1 data1, type2 data2}"

For that, the DWARF reader walks the DIE tree and emit the flat
representation recursively.

But here, because the DIE tree contains a cycle, the code goes into an
endless loop.

There is a similar issue with function types

Note that later, when the libabigail IR is built, we face a similar
problem.

This patch introduces cycle detection & avoidance in the code that
emit type names in the DWARF reader and in the Libabigail IR.  It adds
the libgm2 RPM to the testsuite and self-compares it using abipkgdiff,
in the test-diff-pkg test harness.

	* src/abg-dwarf-reader.cc (die_qualified_type_name)
	(die_qualified_decl_name, die_qualified_type_name_empty)
	(die_function_signature, die_pretty_print_type)
	(die_pretty_print_decl, die_pretty_print)
	(reader::{get_die_qualified_type_name}): Take a new guard
	parameter.  Pass it to all the type name construction function,
	all the way down to die_class_flat_representation and
	die_return_and_parm_names_from_fn_type_die.
	(die_qualified_name, die_type_name)
	(die_class_or_enum_flat_representation)
	(die_class_or_enum_flat_representation)
	(reader::{get_die_pretty_type_representation,
	get_die_pretty_representation}): Add an overload that takes a
	guard parameter and rewrite the previous overload in terms of the
	new one.
	(die_class_flat_representation)
	(die_return_and_parm_names_from_fn_type_die): Take a new guard
	parameter.  Use it to detect and avoid cycles during the
	construction of the type name.
	* src/abg-ir-priv.h
	(class_or_union::priv::is_printing_flat_representation_): Define
	new data member.
	(class_or_union::priv::{set,unset,is}_printing_flat_representation):
	Define member functions.
	(function_type::priv::is_pretty_printing_): Define new data
	member.
	(function_type::priv::{set,unset,}_is_pretty_printing): Define
	member functions.
	* src/abg-ir.cc (get_class_or_union_flat_representation)
	(add_outer_pointer_to_fn_type_expr): Implement cycle detection and
	avoidance for recursive classes and function types.
	* tests/data/test-diff-pkg/libgm2-14.2.1-1.fc40.x86_64-self-check-report.txt:
	New test reference output.
	* tests/data/test-diff-pkg/libgm2-14.2.1-1.fc40.x86_64.rpm: New
	input RPM.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Adjust.
	* tests/data/Makefile.am: Add the new test material to source
	distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the new test inputs
	to the test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
32be4dd23c abidw: Add a --kmi-stablelist option alongside existing --kmi-whitelist
* doc/manuals/abidw.rst: Update the documentation.
	* tools/abidw.cc (display_usage): Add a help string for the new
	--kmi-stablelist.
	(parse_command): Parse it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
0a6ffe1169 dwarf-reader,tools-utils: Add statistics about built/suppressed functions
When running abidw --verbose, it's useful to have information about
the number of functions and variable that were actually constructed or
suppressed.  This is useful to see how effective a suppression
specification that instructs libabigail to drop certains
functions/variables actually is.

This patch emits statistics about the amount of functions/variables
represented in the IR and dropped on the floor.

	* src/abg-dwarf-reader.cc (reader::stats): Define new struct.
	(reader::stats_): Define a new data member of type stats.
	(build_or_get_fn_decl_if_not_suppressed)
	(build_or_get_var_decl_if_not_suppressed): Increments the stats.
	(reader::read_debug_info_into_corpus): Emit the stats about number
	of suppressed/kept functions and variables at the end of the
	corpus building.
	* src/abg-tools-utils.cc (load_vmlinux_corpus): Emit the status
	about the number of functions/variables in the corpus.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
a1d3aafe2f big-tests: Update git sub-module
Update the big-tests git sub module to commit:

commit d84f5ef7b490ffcd466be20052fed87635e6e148
Author: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Date:   Tue Aug 20 14:09:05 2024 +0300

    big-test: Add test for enumerate dicts in an archive

	* big-tests: Update to git commit d84f5ef7b490ffcd466be20052fed87635e6e148

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
6ecf2496ec abilint: Support --verbose option
This new option is useful to show where time is spent, just like what
abidw --verbose does.

	* doc/manuals/abilint.rst: Document the new --verbose option.
	* tools/abilint.cc (options::do_log): New data member.
	(options::options): Initialize it.
	(display_usage): Document it.
	(set_reader_options): New static function to set the options of
	the reader from user-provided options.
	(main): Use the new set_reader_options.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
36f2a4dca9 {btf,ctf,dwarf}-reader, ir: Fix self-comparison debugging for corpus groups
When debugging the self comparison of a corpus group, libabigail fails
to detect that two ABI artifacts belong to the same corpus group.
This is because it only takes into account each individual corpus, not
the fact that several corpora can be grouped into one corpus group.

This patch introduces a new function type_originates_from_corpus which
can detect that a type originates from a corpus or a from a corpus
group.  That function is used to detect that the type being
canonicalized belongs to the ABIXML corpus group and so its canonical
type must match the one of its originating ELF type.

	* src/abg-btf-reader.cc (reader::read_debug_info_into_corpus):
	When reading an ELF binary, which is part of a corpus group, for
	the purpose of self-comparison, set that corpus group as the
	comparison input.  Otherwise, if the ELF binary is not part of the
	corpus group, set its corpus as the comparison input.  This is
	done only when we are debugging the self-comparison process by
	doing abidw --debug-abidiff.
	* src/abg-ctf-reader.cc (reader::read_corpus): Likewise.
	* src/abg-dwarf-reader.cc (reader::read_debug_info_into_corpus):
	Likewise.
	* src/abg-ir-priv.h (type_originates_from_corpus): Declare ...
	* src/abg-ir.cc (type_originates_from_corpus): ... new function.
	(type_base::get_canonical_type_for): When debugging the
	self-comparison process, use the new type_originates_from_corpus
	to know if the current type being canonicalized originates from
	the second corpus.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
6f7335e110 {dwarf,btf,ctf}-reader: Set the origin of the corpus group
Apart from the ABIXML reader, readers don't set the origin of a corpus
group when its read.  Oops.  Fixed thus.

	* src/abg-btf-reader.cc (reader::read_corpus): Set the origin of
	the corpus group being read.
	* src/abg-ctf-reader.cc (reader::read_corpus): Likewise.
	* src/abg-dwarf-reader.cc (reader::read_debug_info_into_corpus):
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
39d7e80555 dwarf-reader: Fix building of void, void* and variadic parm types
This patch adds the IR nodes of void, void* and variadic parm types to
their scope just once.  Also, it schedules them for (sorting, hashing
and) canonicalization just like other types.

	* src/abg-dwarf-reader.cc (build_ir_node_for_void_type)
	(build_ir_node_for_void_pointer_type)
	(build_ir_node_for_variadic_parameter_type): Add the type node to
	its scope just once.  Use
	reader::schedule_type_for_late_canonicalization to canonicalize
	it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
430618c879 tools-utils: Improve logging while reading a Linux kernel
This patch improves time logging while reading a Linux kernel, to help
see where time is spent.

	* src/abg-tools-utils.cc (load_vmlinux_corpus)
	(build_corpus_group_from_kernel_dist_under): Improve time logging.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:44 +02:00
Dodji Seketeli
0da40a678b ir: Improve type logging during type canonicalization
This patch adds logging to show the time taken by type
canonicalization.

	* src/abg-ir-priv.h (canonicalize_types): Log the time taken by
	type canonicalization.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
68d498b9fe reader: Improve logging in the ABIXML reader
This patch improves the logging of the ABIXML reader to better see
where time is spent when reading an ABIXML file.

	* src/abg-reader.cc (reader::read_corpus)
	(reader::perform_type_canonicalization)
	(read_corpus_group_from_input): Improve logging.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
ddb6236e03 dwarf-reader: Support LLVM's lingo of declaration-ness
In the DWARF emitted by LLVM, a type DIE can have the
DW_AT_declaration attribute present (saying that it's a declaration)
and yet have the DW_AT_byte_size present, implying that the type is
defined, at the same time.  OK, in all fairness, a definition is a
declaration too, but then, the DW_AT_declaration attribute becomes a
tad useless on a definition.

Note that in the DWARF emitted by GCC, when a DIE has the
DW_AT_declaration set, if no size attribute is present then Libabigail
considers that it's a declaration, not a definition.

This state of things makes libabigail wrongly think that some types
(especially some enums) are defined, when they are just declarations.
And that leads to self-comparison issues down the road.

For instance, consider this DIE sub-tree from the libLLVM.so of
llvm-libs-17.0.6-5.el9.x86_64:

 [1745df]    namespace            abbrev: 46
             name                 (GNU_strp_alt) "llvm"
             sibling              (ref_udata) [1745fe]
 [1745e5]      class_type           abbrev: 98
               name                 (GNU_strp_alt) "raw_ostream"
               declaration          (flag_present) yes
[...]

 [1745f6]        enumeration_type     abbrev: 116
                 name                 (GNU_strp_alt) "Colors"
                 byte_size            (data1) 4
                 declaration          (flag_present) yes

This "enum Colors" DIE here is a just a declaration, even though it
has a DW_AT_byte_size attribute set.  We see that it has no children
DIE.

But then, later, we can see this DIE sub-tree:

 [484843]    namespace            abbrev: 39
             name                 (GNU_strp_alt) "llvm"
 [484848]      class_type           abbrev: 90
               containing_type      (ref_udata) [484848]
               calling_convention   (data1) pass_by_reference (4)
               name                 (GNU_strp_alt) "raw_ostream"
               byte_size            (data1) 64
               decl_file            (data1) raw_ostream.h (1)
               decl_line            (data1) 52
[...]
 [4848b9]        enumeration_type     abbrev: 125
                 name                 (GNU_strp_alt) "Colors"
                 byte_size            (data1) 4
                 declaration          (flag_present) yes
 [4848bf]        member               abbrev: 108
                 name                 (GNU_strp_alt) "RED"
                 type                 (ref_udata) [485234]
                 decl_file            (data1) raw_ostream.h (1)
                 decl_line            (data1) 110
                 external             (flag_present) yes
                 declaration          (flag_present) yes
                 accessibility        (data1) public (1)
                 const_value          (sdata) 1 (1)
 [4848ca]        member               abbrev: 108
                 name                 (GNU_strp_alt) "GREEN"
                 type                 (ref_udata) [485234]
                 decl_file            (data1) raw_ostream.h (1)
                 decl_line            (data1) 111
                 external             (flag_present) yes
                 declaration          (flag_present) yes
                 accessibility        (data1) public (1)
                 const_value          (sdata) 2 (2)
[...]

Here, we see the actual definition of the "enum Colors" represented
before by DIE 0x1745f6.  The definition is not linked in any way to
the previous declaration.  So the DWARF reader now thinks that both
enum Colors (at DIE 0x1745f6 and 0x4848b9) are two different enums
with the same name.  And of course, that can lead to self-comparison
issues down the road.

In this patch, the DWARF reader is instructed to detect that DIE
0x1745f6 is a declaration, by noticing that it has no children DIE.

Once that was done, I noticed that the pass that resolves declarations
to their definitions is broken.

The pass is broken because declarations are schedule to be processed
by that pass too early, before they got added to their lexical scope.
At that point, the declarations have non-qualified names.  When the
declaration-resolution time comes (after the ABI corpus is fully
constructed), the definitions of these declarations are added to their
lexical scope and thus have fully-qualified names.  So the
declaration-resolution pass looks for definitions by looking up their
non-qualified names (as the declarations had non-qualified names, due
to their early scheduling), and it never finds any because they all
have full-qualified names!

So the patch fixes this by deferring the scheduling of declarations to
the declaration-resolution pass, for after they are added to their
lexical scope.

	* src/abg-dwarf-reader.cc (die_is_declaration_only): A DIE is a
	declaration if it has the DW_AT_declaration property and if it
	either has no size attribute or no children DIE.
	(reader:: maybe_schedule_decl_only_type_for_resolution): Define
	new function.
	(build_enum_type, add_or_update_class_type)
	(add_or_update_union_type): Do not schedule a declaration for
	declaration-to-definition-resolution pass here.
	(build_typedef_type): If the typedef is a naming typedef, schedule
	the underlying type for the declaration-to-definition-resolution
	pass here.
	(build_ir_node_from_die): Schedule the declaration for
	declaration-to-definition-resolution pass here, after it's been
	added to its scope.
	* tests/data/test-diff-filter/test41-report-0.txt: Adjust.
	* 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/test-libandroid.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
d181673b57 ir: Fix name setting of a ptr-to-mbr-type
The name of a pointer to member type is currently set at the time of
construction of the type.

This can be problematic because at the time of construction of the
type, the member type might not be yet fully constructed.  That would
result in a name (for the pointer to member type) that is incorrect
and stays incorrect for the lifetime of the ptr-to-mbr-type.

To be correct, the name of the pointer to member type must always
reflect the current state of the member and containing types.

This patch does just that.

The patch turns decl_base::get_name into a virtual member function.
It then creates a ptr_to_mbr_type::get_name virtual member function
that dynamically overloads decl_base::get_name.  Then,
ptr_to_mbr_type::get_name just builds and returns the qualified name
of the pointer to member type.

	* include/abg-ir.h (decl_base::{g,s}et_name): Make these member
	functions virtual.
	(ptr_to_mbr_type::get_name): Add new virtual overload.
	* src/abg-ir.cc (ptr_to_mbr_type::ptr_to_mbr_type): Do not set the
	name of the type here.  Just say that it's not anonymous.
	(ptr_to_mbr_type::get_name): Define new (virtual) member function.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
6381bbebe6 dwarf-reader: Speed-up decl-only resolution
After the IR is constructed, decl-only classes and enums are resolved
to their definition, for cases where the link between the declaration
and the definition is not obviously stated in the DWARF
representation.

During that resolution, it often happens that types are compared.  As
that comparison happens before type canonicalization, the comparison
is structural.  So it takes time and it can take forever.

As pre-canonicalization type comparison happens between artifacts that
are from the same binary, we can consider that two types of the same
name and kind having the same source location are equivalent.

This optimization speeds up things A LOT.  So much so that
self-comparing the usr/libexec/gcc/s390x-redhat-linux/12/gnat1 binary
(from the gcc-gnat package) now takes less than 4 minutes, down from
more than one hour!

	* src/abg-dwarf-reader.cc
	(reader::compare_before_canonicalisation): If the two types being
	compared are of the same kind and name, and are declared at the
	same source location, then they ought to be equivalent.
	* tests/data/test-annotate/test14-pr18893.so.abi: Adjust.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: 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.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
a75424b6e5 reader: Avoid duplicating recursive types
Sometimes, building a sub-type of a complex type can trigger the
building of the complex type itself.  This is in the case of a
recursive complex type where one of its sub-types has the complex type
as a sub-type.

In those cases, the complex type should not be duplicated.  This patch
ensures that.

	* src/abg-reader.cc (build_qualified_type_decl)
	(build_pointer_type_def, build_reference_type_def)
	(build_ptr_to_mbr_type, build_subrange_type, build_array_type_def)
	(build_enum_type_decl, build_typedef_decl): After a sub-type is
	built, check if the complex type we are looking at is built too.
	If it is, then return it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
217ba7fdb8 dwarf-reader: Avoid duplicating anonymous member types
Sometimes, anonymous member types are duplicated in some classes read
by the DWARF reader.  This is because the DWARF reader doesn't lookup
anonymous member types in their class scope before adding them into
their scope.

This patch teaches the DWARF reader how to name an anonymous class,
union or enum by using its flat pretty representation, e.g:

    struct {int blah; char meh;}

That flat representation is used as the name of the anonymous type to
look it up in a given class scope before adding it to that scope.  If
the scope already contains the type, then the type is not added.

Now that class scopes have their proper anonymous member types, it
appeared that the filtering of change reports needed a number of
adaptations because we are now seeing things that we were not seeing
before.  For instance two new change categories
NON_COMPATIBLE_DISTINCT_CHANGE_CATEGORY and
NON_COMPATIBLE_NAME_CHANGE_CATEGORY are added.  The former is for a
change where a given type becomes another type of a different kind in
an non-compatible way.  For instance, a struct type becomes an enum
type.  The later category is for a change in a name of the type,
resulting in a non-compatible change.  Thus, new non-compatible
changes can now be categorized and reported as such.

	* include/abg-comp-filter.h (has_void_ptr_to_ptr_change)
	(has_harmless_enum_to_int_change)
	(has_benign_array_of_unknown_size_change): Declare new functions.
	* include/abg-comparison.h (enum diff_category): Add
	NON_COMPATIBLE_DISTINCT_CHANGE_CATEGORY,
	NON_COMPATIBLE_NAME_CHANGE_CATEGORY enumerators.  Update the other
	enumerator values.  Also, update the EVERYTHING_CATEGORY
	enumerator value.
	* include/abg-ir.h (class_decl::find_base_class): Document the
	name of the parameter.
	* src/abg-comp-filter.cc (type_diff_has_cv_qual_change_only)
	(is_non_compatible_distinct_change, is_void_ptr_to_ptr): Define
	new static functions.
	(has_subtype_changes): Remove static function.
	(class_diff_has_only_harmless_changes): Do not bother checking if
	the class_diff has subtype changes.  If there are, the category of
	those changes is going to be propagated upward to this current
	diff node.  Update the comments.
	(has_harmless_name_change): A diff node carrying compatible types
	or types that differ only from their CV qualifiers should qualify
	as having a harmless name change.
	(has_harmless_enum_to_int_change): Make this function be
	non-static.
	(type_diff_has_cv_qual_change_only): Introduce an overload that
	takes two ABI artifacts instead of one diff node.  Make the diff
	node overload use the new one.  Simplify logic by essentially
	peeling off qualified or typedefs first.  Then if what remain is
	pointer or array types, look at their underlying types.  If the
	remaining underlying types are equal then return true.
	(has_void_ptr_to_ptr_change): Use the new is_void_ptr_to_ptr
	function.  This allows the function to detect void* -> pointer and
	pointer -> void* changes.  And it simplifies the logic.
	* src/abg-comparison.cc (distinct_diff::compatible_child_diff):
	Build a compatible child diff node iff the two diff subject are
	actually compatible meaning, they are equal modulo a typedef.
	(get_default_harmful_categories_bitmap): Add the new
	abigail::comparison::{NON_COMPATIBLE_DISTINCT_CHANGE_CATEGORY,NON_COMPATIBLE_NAME_CHANGE_CATEGORY}
	enumerators to the bitmap of harmful categories.
	(operator<<(ostream& o, diff_category c)): Update this to support
	emitting the new
	abigail::comparison::{NON_COMPATIBLE_DISTINCT_CHANGE_CATEGORY,NON_COMPATIBLE_NAME_CHANGE_CATEGORY}
	enumerators.
	(class_or_union_diff::priv::count_filtered_{subtype_}changed_dm):
	Fix logic for counting local changes.
	diff::has_local_changes_to_be_reported is not reliable so do not
	rely on it.  We might want to remove that function in the end.
	(category_propagation_visitor::visit_end): If the current diff
	node has a harmless void pointer to pointer, enum to int, or a
	benign array of unknown size change, do not propagate the
	NON_COMPATIBLE_{NAME,DISTINCT}_CHANGE_CATEGORY that have
	necessarily bubbled up from some of their distant children nodes.
	* src/abg-dwarf-reader.cc
	(maybe_set_member_type_access_specifier)
	(get_next_member_sibling_die): Declare this pre-existing static
	function.
	(get_internal_anonymous_die_name)
	(lookup_class_typedef_or_enum_type_from_corpus)
	(lookup_class_typedef_or_enum_type_from_corpus): Remove.
	(die_return_and_parm_names_from_fn_type_die): Add is_method_type
	and return_type_name parameters. Fix the representation of member
	functions.
	(die_function_signature): Add qualified_name parameter. Adjust
	call to die_return_and_parm_names_from_fn_type_die.
	(die_type_name, die_enum_flat_representation)
	(die_class_flat_representation)
	(die_class_or_enum_flat_representation): Define new static
	functions.
	(reader::get_die_qualified_type_name, die_qualified_type_name):
	For anonymous class or enum types, use the new
	die_class_or_enum_flat_representation.  Adjust the call to
	die_return_and_parm_names_from_fn_type_die. For function types fix
	the name representation.
	(die_pretty_print_type): Adjust call to
	die_return_and_parm_names_from_fn_type_die.
	(die_pretty_print_decl): Take qualified_name and include_fns
	parameters.  Use the new die_type_name for variable type names.
	Adjust call to die_function_signature.
	(die_pretty_print): Adjust call die_pretty_print_decl.
	(get_member_child_die): Remove useless vertical space.
	(build_enum_underlying_type): Sort this enum underlying type (and
	potentially hash it) before canonicalizing it.
	(add_or_update_class_type): If an anonymous type is in the global
	scope, take that into account when building its internal anonymous
	die name.  Lookup anonymous member types before adding them to the
	class scope to avoid duplicating them in their scope.
	(add_or_update_union_type): Likewise, lookup anonymous member
	types before adding them to the union scope to avoid duplicating
	them in their scope.
	(build_subranges_from_array_type_die): Const-ify the input reader.
	Adjust call to build_ir_node_from_die.  Associate the subrange DIE
	to the IR node built.
	(build_ir_node_from_die): Get the current corpus from the reader
	because it might be set for scope passed to this function, or the
	scope might be nullptr.  Schedule base types for canonicalization
	like all the other types.  Also, lookup all class/union types
	before adding them to their class scope.
	* src/abg-leaf-reporter.cc (leaf_reporter::report): In the
	overload for class_or_union_diff, report changed data members and
	their sub-types.
	* tests/Makefile.am: Do not XFAIL the test runtestabidiffexit.  No
	more tests are XFAILED.  All tests should now pass.
	* tests/data/test-abidiff-exit/PR30503/libsdl/libsdl-1.2.60-1.2.64-report.txt:
	Adjust.
	* tests/data/test-abidiff-exit/PR31513/reported/PR31513-reported-report-1.txt:
	Likewise.
	* tests/data/test-abidiff-exit/qualifier-typedef-array-report-1.txt:
	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/test0.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.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/PR25058-liblttng-ctl-report-1.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test4-report.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/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/test41-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test5-report.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/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/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/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/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
2ebe28b77e ir: Cache the result of scope_decl::get_sorted_member_types
Speed up ABIXML emitting by caching the result of
scope_decl::get_sorted_member_types when it's called on a
canonicalized type.

	* include/abg-ir.h
	(environment::canonicalization_started): Define new member
	functions.
	* src/abg-ir-priv.h
	(environment::priv::canonicalization_started_): Define new data
	member.
	(canonicalize_types): Call
	environment::canonicalization_started(true) right before starting
	type canonicalization and call
	environment::canonicalization_started(false) right after type
	canonicalization is done.
	* src/abg-ir.cc (environment::canonicalization_started): Define
	new methods.
	(environment::canonicalization_is_done): Set the
	new canonicalization_started flag to false when the
	canonicalization is done.
	(scope_decl::priv::clear_sorted_member_types_cache_): Declare new
	data member.
	(scope_decl::{add_member_decl, insert_member_type}): If we are
	adding a type to the scope, then flag the scope as needing to
	clear the sorted member types cache.
	(scope_decl::get_sorted_member_types): If type canonicalization is
	not yet started, then the sorted member types cache needs to be
	cleared.  If the sorted member types cache is to be cleared, then
	clear it.  If the cache is empty, fill it.  Then return the
	content of the cache.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
923b40893a reader: Avoid duplicating member types
When a member type is already present in a class scope, do not add it
again.

	* src/abg-reader.cc (read_name): New static function.
	(build_class_decl, build_union_decl): If a member type already
	exists in the class, do not add it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
88b2e88b19 Don't strip typedefs in fn names when pretty-printing and comparing
This removes a kludge that was needed to avoid spurious changes back
when we didn't have hashing based comparison for type
canonicalization.

If, in the future, we remove the type name based comparison speed
optimization during canonicalization, this patch will be even more
relevant.  For now, it greatly simplifies the code base already and it
fixes several issues from the type hashing patch, so much so that
runtestdiffpkg and runtestdifffilter now PASS.  runtestabidiffexit
still fails so it's still XFAILed.

	* src/abg-ir.cc (get_function_type_name, get_method_type_name): Do
	not peel typedef from return type.
	(equals): In the overload for function_type, do not peel typedef
	before comparing return types. In the overload for
	function_decl::parameter, do not peel typedef before comparing the
	parameter type.
	(stream_pretty_representation_of_fn_parms): Do not strip typedef
	from parameter types.
	(add_outer_pointer_to_fn_type_expr): Likewise for return type.
	* tests/Makefile.am: XFAIL the test runtestabidiffexit.
	* tests/data/test-abidiff-exit/PR30503/libsdl/libsdl-1.2.60-1.2.64-report.txt:
	Adjust.
	* tests/data/test-abidiff-exit/PR31513/reported/PR31513-reported-report-1.txt:
	Likewise.
	* tests/data/test-abidiff-exit/pointer-to-member/test-ptr-to-mbr2-output-1.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-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-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/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/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>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
681db67284 comp-filter: Ignore ptr size when detecting void ptr to ptr change
Note that the output of the test runtestdifffilter has been
ameliorated as void pointer to pointer changes are now completely
ignored.

There are still 2 tests that fail after this patch so they are still
XFAILed: runtestdiffpkg and runtestabidiffexit.  They
are going to be addressed by subsequent patches.

	* src/abg-comp-filter.cc (has_void_ptr_to_ptr_change): Ignore
	pointer size when detecting void pointer to pointer change.
	* tests/data/test-diff-filter/test47-filter-void-ptr-change-report-0.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
d18ff748d7 comp-filter: Consider lvalue-ness changes on references as harmful
This patch detects an lvalue-ness change on a reference type,
categorizes it as REFERENCE_LVALUENESS_CHANGE_CATEGORY and considers
it as harmful by default.

Note that this patch fixes the parts of runtestdifffilter that have to
do with lvalue-ness changes to reference types, but there is still one
test failing from the testsuite: runtestabidiffexit.  This test has
been XFAILed in the test suite.

	* include/abg-comparison.h (enum diff_category): Add the new
	REFERENCE_LVALUENESS_CHANGE_CATEGORY enumerator.  Adjust the value
	of the other enumerators.
	* src/abg-comparison.cc (get_default_harmful_categories_bitmap):
	Consider the new REFERENCE_LVALUENESS_CHANGE_CATEGORY as being
	part of the default harmful categories bitmap.
	(operator<<(ostream& o, diff_category c)): Support the new
	REFERENCE_LVALUENESS_CHANGE_CATEGORY for me.
	* include/abg-comp-filter.h (has_lvalue_reference_ness_change):
	Declare new function.
	* src/abg-comp-filter.cc (has_lvalue_reference_ness_change):
	Define new function.
	(categorize_harmful_diff_node): Use the new
	has_lvalue_reference_ness_change to set the new
	REFERENCE_LVALUENESS_CHANGE_CATEGORY.
	* tests/Makefile.am: XFAIL runtestabidiffexit.
	* tests/data/test-diff-filter/test3-report.txt: Adjust.
	* 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/test35-pr18754-no-added-syms-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test47-filter-void-ptr-change-report-0.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
ff6e09dde3 ir: decl-only classes don't equal fully defined classes under ODR
Until now, when the One Definition Rule is in effect (when analyzing
C++, for instance) we assume that a decl-only class equals all the
fully-defined classes of the same name.  Now that we are using type
hashing to determine type equality during type canonicalization, we
cannot keep that assumption, because the hash of a decl-only class
does not necessarily equals the hash of its definition.  Actually,
decl-only classes don't have hashes.  So this patch removes that
assumption.

Note that even with this patch, "make check" still yields 3 failures
that are still XFAILed in the test suite.

	* src/abg-ir.cc (equals): In language supporting the ODR (just
	like in all other languages), consider that a decl-only class is
	different from its defined class counterpart.
	* tests/data/test-diff-dwarf/test28-vtable-changes-report-0.txt:
	Adjust.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
1b1b8399d1 ir: Remove the now useless type propagation optimization
Now that the type hashing patch is in, I figure we can do away with
the overly complicated type propagation optimization.  The type
propagating optimization is disabled by the type hashing patch anyway
so this is overdue now.

The nice thing about this is that we are dropping a big complicated
code with no noticeable speed penalty \o/

	* configure.ac: Remove the now useless --enable-ct-propagation
	option.
	* include/abg-ir.h (environment::do_on_the_fly_canonicalization):
	Remove member function declaration.
	* src/abg-ir-priv.h (type_base::priv::{depends_on_recursive_type_,
	canonical_type_propagated_,
	propagated_canonical_type_confirmed_}): Remove data members.
	(type_base::priv::priv): Update.
	(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,
	propagated_canonical_type_confirmed,
	set_propagated_canonical_type_confirmed,
	clear_propagated_canonical_type}): Remove member functions.
	(environment::priv::{types_with_non_confirmed_propagated_ct_,
	recursive_types_, types_with_cleared_propagated_ct_,
	do_on_the_fly_canonicalization_}): Remove data members.
	(environment::priv::priv): Adjust.
	(environment::priv::{mark_dependant_types,
	mark_dependant_types_compared_until}): Update comment.
	(environment::priv::{mark_dependant_types,
	mark_dependant_types_compared_until, is_recursive_type,
	propagate_ct, confirm_ct_propagation_for_types_dependant_on,
	confirm_ct_propagation, confirm_ct_propagation,
	types_with_cleared_propagated_ct,
	types_with_cleared_propagated_ct,
	record_type_with_cleared_propagated_canonical_type,
	erase_type_with_cleared_propagated_canonical_type,
	collect_types_that_depends_on,
	cancel_ct_propagation_for_types_dependant_on,
	cancel_ct_propagation, clear_propagated_canonical_type,
	add_to_types_with_non_confirmed_propagated_ct,
	remove_from_types_with_non_confirmed_propagated_ct,
	cancel_all_non_confirmed_propagated_canonical_types}): Remove.
	(canonicalize_types): Remove canonical type propagation debugging
	code.
	* src/abg-ir.cc (mark_dependant_types_compared_until): Remove function.
	(RETURN_TRUE_IF_COMPARISON_CYCLE_DETECTED): Adjust, do not use the
	removed mark_dependant_types_compared_until.
	(return_comparison_result): Remove handling of the canonical type
	propagation optimization.
	(environment::do_on_the_fly_canonicalization): Remove member
	functions.
	(maybe_propagate_canonical_type, maybe_propagate_canonical_type)
	(maybe_cancel_propagated_canonical_type, ): Remove functions.
	(compare_canonical_type_against_candidate, canonicalize): Remove
	handling of the canonical type propagation optimization.
	(equals): In the overload for class_or_union, adjust call to
	return_comparison_result.  In the overload for class_decl, remove
	call to maybe_cancel_propagated_canonical_type.
	(OnTheFlyCanonicalization): Remove this doxygen documentation
	module describing the canonical type propagation optimization.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
ccc71fc0e0 Implement type hashing
The order in which types of the same name & kind (aka homonym types)
are canonicalized does have an impact on the final canonicalization
result.  This variation is at the root of the self-comparison error
happening on the gcc-gnat package in f37.  The command to reproduce
the issue is:

	$ fedabipkgdiff  -a --self-compare --from fc37 gcc-gnat

Note that the binary on which self-comparison is failing is gnat1 for
the s390 arch:

    $ pwd
    ~/git/libabigail/hash-types/prtests/extracts/gcc-gnat-12.3.1-1.fc37.s390x
    $
    $ abidw --debug-abidiff -d usr/lib/debug usr/libexec/gcc/s390x-redhat-linux/12/gnat1

That test is still failing with this patch, but is going to pass with
subsequent patches in the series.

Having persistent hashes that can be serialized along with the types
into ABIXML does help to suppress that variation.

This patch implements that idea.

Learning from the teachings of the DWZ tool, the patch uses the xxhash
algorithm for primitive hashing and hash combination.  The patch
prevents cycling while hashing type graphs by maintaining a hashing
state in objects being hashed, just like what DWZ does.

The patch cleans out the relics of the previous (failed) attempt of
using hashing in the IR.  Now, a virtual
type_or_decl_base::hash_value() is declared and implemented by
decl_base, type_base and descendants of type_base.

Each IR node has a "private" hashing function that knows how to hash
the specific parts of the IR node and combine the hashes of its
sub-type IR children nodes to come up with a hashing value for the
whole IR node, while preventing cycling.  There are some subtleties
introduced during the hashing.  For instance, a typedef hash is the
same as the hash of its underlying type.  This helps the hash value of
a pointer or reference to a typedef of class to be the same as the
hash value of a pointer or reference to the class.  Another subtlety
is to never hash the declaration of a class, if a definition is
present; rather, always hash the definition.  In general, types that
are not canonicalized (for which is_non_canonicalized_type returns
true) are not hashed.

That private hashing function is thus used by the ::hash_value()
of the IR node to compute the hash value for the first time and cache
it for it subsequent invocations.

After building the IR, the patch first sorts all types, then hashes
them and then canonicalizes them.  During the canonicalization phase,
two types with different hashes are deemed different.  Two types with
the same hash are compared structurally.

During ABIXML de-serialization, libabigail reads the hash value back
from each IR node and uses that instead of re-calculating the hash.

Note that calculating the hash of a node read from ABIXML could lead
to a different result than calculating the hash for the same node from
DWARF, because the order in which hashes are calculated counts,
especially for recursive types.  That is one of the reasons why hashes
are not re-calculated when reading from abixml.

In all fairness, I think we would need to test this hypothesis again,
because we now sort types before hashing them, so in theory, the
hashing should yield the same result as when done from ELF.
Regardless, just reading the hash values from ABIXML is faster than
re-calculating it.  We might want to re-calculate the hashes for
debugging purposes, however.  This is left as an exercise for the
astute reader of this patch.

If the hash of an ABIXML node equals the hash of an ELF node, then
during type canonicalization, the two nodes are compared structurally.
If the hashes are different, then the nodes compare different during
canonicalization.  That speeds up canonicalization at ABIXML reading
time.  But this implies that each change in a hashing scheme should
result in a change in the major ABIXML version number, rendering newer
ABIXML files incompatible with previous ones.  It even makes them
incompatible with newer libabigail code altogether.  In that case, we
might want to teach abidiff about ABIXML versioning, even when
comparing an ABIXML input against an ELF one.

Note that the patch uses the hashing during type canonicalization in
general; that is, if the hashes are present and different, then the
types are different.  That helps to do away with the need for the
"canonical type propagation" optimization that I suspect is causing
issues on redundant types.

It turns out that not using that optimization doesn't incur any
noticeable speed penalty so in a subsequent patch, that canonical type
propagation optimization code is going to be entirely removed.

The patch uses an optional value for hashes, to make the difference
between no-hash (for recursive sub-types and types supposed to have no
hash/canonical types) and a hash value of zero which is a valid hash
value.

Note that the patch emits hashes for function-decl elements.  This is
the hash of the type of the function.  When parsing ABIXML, the reader
sets that function-decl hash to the function_type built from it.

Also, note that for types having the same representation (homonym
types) and yet are canonically different, this patch emits a distinct
canonical type index (aka CTI).  That CTI is appended to the hash
value, following a "#" sign.

Later, during type canonicalization, two homonym types T and T' (where
T originates from ELF and T' originates from ABIXML) having the same
hash and CTI will be structurally compared.  If T equals T', then T
and T' will be considered canonically equivalent.  In other words,
CTIs help to match homonym types originating from ABIXML against
homonym types originating from ELF.

Note that 2 tests are still failing. They are fall-outs that are
addressed in subsequent patches.  This patch XFAIL them until they get
fixed by subsequent patches of the series.

	* configure.ac: Bump ABIXML version to 4.0.  Detect the new xxhash
	dependency and require the 0.8.0 version at minimum.
	* include/abg-fwd.h (look_through_decl_only_type): Declare new
	functions.
	(is_scope_decl): Const-ify the parameter and
	the returned value.  Also, do not include "abg-hash.h" here.
	* include/abg-hash.h: Make this include cstdint (for uint64_t) and
	abg-ir.h, instead of stdint.h.
	(enum hashing_state): Define new enum in the abigail::hashing
	namespace.
	(combine_hashes, fnv_has, hash, get_hashing_state)
	(set_hashing_state, is_recursive_artefact): Declare new functions
	in the abigail::hashing namespace.
	(struct {decl_base, type_base, type_decl, qualified_type_def,
	pointer_type_def, reference_type_def, ptr_to_mbr_type,
	array_type_def, enum_type_decl, typedef_decl, function_type,
	method_type, member_base, class_or_union, class_decl::base_spec,
	class_decl, union_decl}::hash): Declare new hash functors in the
	abigail::ir namespace.
	* include/abg-ir.h: Remove the inclusion of abg-hash.h from this
	header.
	(typedef hash_t): Define new type.
	(peek_hash_value): Declare new function.
	(get_canonical_types): Return a pointer to const vector.
	({type_or_decl_base, type_base, qualified_type_def,
	pointer_type_def, reference_type_def, ptr_to_mbr_type,
	array_type_def::subrange_type, typedef_decl, function_type,
	method_type, class_or_union, class_decl, class_decl::base_spec,
	union_decl}::hash_value): Add new virtual member functions.
	(type_or_decl_base::set_hash_value): Add new member function.
	(type_or_decl_base::priv_): Make this data member public.
	(peek_hash_value, set_or_get_cached_hash_value): Declare these
	functions as friends of class type_or_decl_base.
	({decl_base, scope_decl, var_decl, function_decl,
	function_decl::parameter}::get_hash): Remove member functions.
	* src/abg-comparison-priv.h (types_or_decls_hash::operator()):
	Adjust to using the new hash_t type.
	* src/abg-ctf-reader.cc
	(reader::{additional_types_to_canonicalize, types}): Add new data
	members.
	(reader::add_type(): Add new member function.
	(reader::canonicalize_all_types): Use the new types vector data
	member to stash types to be canonicalized and pass them to
	ir::hash_and_canonicalize_types for canonicalization.
	(process_ctf_base_type)
	(build_ir_node_for_variadic_parameter_type)
	(build_ir_node_for_void_type, build_ir_node_for_void_pointer_type)
	(build_array_ctf_range, process_ctf_enum_type): Do not use
	canonicalize anymore.  Rather, rely on reader::add_type to
	schedule types for canonicalization, doing the generic sorting and
	hashing before doing the actually canonicalization.
	* src/abg-dwarf-reader.cc ({dwarf_offset_pair_hash,offset_hash,
	offset_pair_hash}::operator()): Use the new hashing function.
	(reader::read_debug_info_into_corpus): Improve logging.  Use
	ir::hash_and_canonicalize_types in lieu of ir::canonicalize_types.
	(reader::types_to_canonicalize): Add
	non-const overload.
	(reader::canonicalize_types_scheduled): Add better logs & misc
	obvious cleanup.
	(maybe_canonicalize_type): Force scheduling canonicalization of
	all types at the end of the DWARF processing.
	* src/abg-hash.cc (combine_hashes, hash, get_hashing_state)
	(set_hashing_state, is_recursive_artefact): Define new functions.
	(MAYBE_RETURN_EARLY_FROM_HASHING_TO_AVOID_CYCLES)
	(MAYBE_FLAG_TYPE_AS_RECURSIVE)
	(MAYBE_RETURN_EARLY_IF_HASH_EXISTS): Define new macros.
	(struct {decl_base, type_base, type_decl, qualified_type_def,
	pointer_type_def, reference_type_def, ptr_to_mbr_type,
	array_type_def, ptr_to_mbr_type, enum_type_decl, typedef_decl,
	function_decl, function_type, method_type, member_base,
	class_or_union, class_decl::base_spec, class_decl,
	union_decl}:#️⃣:operator): Define new hash functors.
	({template_parameter, template_decl, non_type_tparameter,
	template_tparameter, type_composition, type_composition,
	function_tdecl}::{hash, dynamic_hash, shared_ptr_hash): Remove.
	* src/abg-ir-priv.h: Don't include abg-ir.h anymore, rather
	include abg-hash.h.
	(struct type_or_decl_base::priv): Move this here, from abg-ir.cc.
	(type_or_decl_base::priv::{hashing_state_, hash_value_,
	is_recursive_artefact_}): Define new data members.
	(type_or_decl_base::priv::{get_hashing_state, set_hashing_state,
	set_hash_value, force_set_hash_value, is_recursive_artefact}):
	Define new member functions.
	(struct sort_for_hash_functor): Define new functor.
	(do_hash_value, set_or_get_cached_hash_value)
	(hash_and_canonicalize_types, sort_and_canonicalize_types): Define
	new function templates.
	(type_is_suitable_for_hash_computing)
	(sort_types_for_hash_computing_and_c14n)
	(get_canonical_type_index, get_decl_name_for_comparison): Declare
	new functions.
	(type_base::priv::canonical_type_index): New data member.
	(type_base::priv::{priv, clear_propagated_canonical_type}):
	Initialize it.
	(uint64_t_pair_hash::operator()): Adjust.
	(environment::priv::number_of_canonical_types): New data member.
	(environment::priv::priv): Initialize it.
	(environment::priv::get_new_canonical_type_index): New member
	function.
	(environment::priv::propagate_ct): Propagate the CTI too.
	(environment::priv::{confirm_ct_propagation_for_types_dependant_on,
	confirm_ct_propagation}): Assert that canonical type has been
	propagated and thus we have a canonical type.
	(struct type_topo_comp::operator()): Beef up sorting of types.
	Take into account the absolute path of the TU, the hash value, the
	CTI)
	(struct sort_for_hash_functor): Define new functor.
	(sort_types_for_hash_computing_and_c14n): Declare new function
	template and new overload.
	(canonicalize_types): Take new do_log and show_stats parameters.
	Improve logging.  Do not sort types in here.
	(hash_and_canonicalize_types): Define new function template.  This
	one does the sorting before the hashing and the canonicalization.
	(sort_and_canonicalize_types): Likewise, but this one does no
	hashing.
	(cache_type_comparison_result): Cache the result of the comparison
	now, unconditionally.  As we don't do canonical type propagation
	anymore, we should not get canonical types and equality to
	disagree anymore.
	(* src/abg-ir.cc (try_canonical_compare): If hash values are
	present and different then the two types are different.
	(environment::get_canonical_types): Constify return value.
	(environment::get_canonical_type): Adjust.
	(struct type_or_decl_base::priv): Move this to abg-ir-priv.h.
	(type_or_decl_base::hashing_started): Remove.
	({decl_base, scope_decl, var_decl, function_decl,
	function_decl::parameter, class_decl::base_spec,
	non_type_tparameter, type_composition}::get_hash): Likewise.
	({template_parameter}::get_hashing_has_started)
	(template_parameter::set_hashing_has_started): Likewise.
	(type_or_decl_base::{hash_value, set_hash_value})
	({type_base, type_decl, qualified_type_def, pointer_type_def,
	reference_type_def, ptr_to_mbr_type,
	array_type_def::subrange_type, array_type_def, enum_type_decl,
	typedef_decl, function_type, method_type, class_or_union,
	class_decl::base_spec, class_decl, union_decl}::hash_value):
	Define new member functions.
	(type_or_decl_base::set_hash_value): Likewise.
	(get_decl_name_for_comparison): Make this non-static.
	(is_scope_decl): Constify.
	(type_is_suitable_for_hash_computing)
	(peek_hash_value, read_type_hash, read_hash_and_stash)
	(look_through_decl_only_type)
	(candidate_matches_a_canonical_type_hash)
	(sort_types_for_hash_computing_and_c14n): Define new functions.
	(lookup_pointer_type, lookup_reference_type)
	(pointer_type_def::get_qualified_name)
	(reference_type_def::get_qualified_name)
	(reference_type_def::get_pretty_representation): Adjust.
	(get_type_name):  Better handle naming of anonymous type decls,
	used for enums.
	(get_debug_representation): Adjust to emit hashes & CTI of types
	as well as member types while debugging.
	(look_through_decl_only_type): Rename look_through_decl_only into
	this.
	(lookup_pointer_type, lookup_reference_type)
	(reference_type_def::get_qualified_name): Adjust.
	(compare_canonical_type_against_candidate): Stop doing canonical
	type propagation during type canonicalization.
	(type_base::get_canonical_type_for): Use the new
	candidate_matches_a_canonical_type_hash.  Set the canonical type
	index for homophone canonical types.  In debug mode, check that if
	a type equals a canonical type, their hash value must match.
	(canonicalize): Take new do_log and show_stats parameter.  Improve
	logging.  Also, a type must have the same CTI as its canonical
	type.
	(hash_type_or_decl): Adjust to use the new type
	hash_t.
	(type_topo_comp::operator()): Add an overload for type_base_wptr.
	If the two pointers are equal, get out early.  Otherwise, if
	everything else is equal, sort using the absolute path of the
	containing translation unit.
	(maybe_propagate_canonical_type): Propagate canonical type only if
	their CTI match.
	* src/abg-reader.cc (maybe_canonicalize_type): Improve logging.
	Schedule all types for late canonicalization.
	(reader::perform_type_canonicalization): Improve logging.  Call
	hash_and_canonicalize_types to hash and canonicalize types.
	(read_type_hash_and_cti, read_hash_and_stash): Define new static
	functions.
	(build_function_decl, build_type_decl)
	(build_qualified_type_decl)
	(build_pointer_type_def, build_reference_type_def)
	(build_ptr_to_mbr_type, build_function_type, build_subrange_type)
	(build_array_type_def, build_enum_type_decl, build_typedef_decl)
	(build_class_decl, build_union_decl): Read and set the hash value
	from ABIXML.
	(build_function_decl, build_qualified_type_decl)
	(build_pointer_type_def, build_reference_type_def)
	(build_function_type, build_subrange_type, build_array_type_def)
	(build_enum_type_decl, build_typedef_decl, build_class_decl)
	(build_union_decl): Read the hash and CTI and set them to the
	type.
	(build_reference_type_def): Build the referenced type before-hand.
	(build_class_tdecl, build_type_tparameter, build_type_composition)
	(build_template_tparameter, build_type, handle_type_decl)
	(handle_qualified_type_decl, handle_pointer_type_def)
	(handle_reference_type_def, handle_function_type)
	(handle_array_type_def, handle_enum_type_decl)
	(handle_typedef_decl, handle_class_decl, handle_union_decl):
	Adjust to the use of the new maybe_canonicalize_type signature.
	* src/abg-btf-reader.cc (reader::canonicalize_types): Use the new
	hash_and_canonicalize_types defined above.  Log the time taken by
	type canonicalization.
	* src/abg-ctf-reader.cc (reader::{types,
	additional_types_to_canonicalize}): New data members
	(reader::add_types): New member functions.
	(reader::canonicalize_all_types): Use the new
	hash_and_canonicalize_types defined above.
	(process_ctf_base_type): Do not call canonicalize here.
	(build_ir_node_for_variadic_parameter_type)
	(build_ir_node_for_void_type)
	(build_ir_node_for_void_pointer_type, process_ctf_enum_type):
	Likewise, and call reader::add_type instead.
	* src/abg-dwarf-reader.cc ({dwarf_offset_pair_hash, offset_hash,
	offset_pair_hash}::operator()): Adjust to using the new hash_t
	type.
	(reader::canonicalize_types_scheduled): Use the new
	hash_and_canonicalize_types above.
	(maybe_canonicalize_type): Schedule all types for late
	canonicalization.
	* src/abg-writer.cc (reader::get_id_for_type): Constify the
	parameter.
	(write_type_hash_and_cti, write_common_type_info)
	(write_fn_parm_and_return_types): Define new static functions.
	(write_type_decl, write_qualified_type_def)
	(write_pointer_type_def, write_reference_type_def)
	(write_array_subrange_type, write_array_type_def)
	(write_enum_type_decl, write_typedef_decl, write_function_decl)
	(write_function_type, write_class_decl_opening_tag)
	(write_union_decl_opening_tag): Emit hash value and CTI to the
	ABIXML.
	* tests/Makefile.am: XFAIL the tests runtestdifffilter and
	runtestabidiffexit for now.
	* tests/data/test-abidiff-exit/PR30329/PR30329-report-1.txt:
	Adjust.
	* tests/data/test-annotate/PR29443-missing-xx.o.annotated.abi:
	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/test-pointer-to-member-1.o.annotated.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-annotate/test3.so.abi: Likewise.
	* tests/data/test-annotate/test4.so.abi: Likewise.
	* tests/data/test-annotate/test5.o.abi: Likewise.
	* tests/data/test-annotate/test6.so.abi: Likewise.
	* tests/data/test-annotate/test7.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi:
	Likewise.
	* tests/data/test-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-filter/test-PR26739-2-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test3-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/test43-decl-only-def-change-leaf-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg-ctf/gmp-6.x.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-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-btf/test0.o.abi: Likewise.
	* tests/data/test-read-btf/test1.o.abi: Likewise.
	* tests/data/test-read-ctf/PR27700/test-PR27700.abi: Likewise.
	* tests/data/test-read-ctf/test-PR26568-1.o.abi: Likewise.
	* tests/data/test-read-ctf/test-PR26568-2.o.abi: Likewise.
	* tests/data/test-read-ctf/test-alias.o.abi: Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-A.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-B.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-anonymous-fields.o.abi: Likewise.
	* tests/data/test-read-ctf/test-array-mdimension.abi: Likewise.
	* tests/data/test-read-ctf/test-array-of-pointers.abi: Likewise.
	* tests/data/test-read-ctf/test-array-size.abi: Likewise.
	* tests/data/test-read-ctf/test-bitfield-enum.abi: Likewise.
	* tests/data/test-read-ctf/test-bitfield.abi: Likewise.
	* tests/data/test-read-ctf/test-callback.abi: Likewise.
	* tests/data/test-read-ctf/test-callback2.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-const-array.abi: Likewise.
	* tests/data/test-read-ctf/test-dynamic-array.o.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-many.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-symbol.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-enum.o.abi: Likewise.
	* tests/data/test-read-ctf/test-fallback.abi: Likewise.
	* tests/data/test-read-ctf/test-forward-type-decl.abi: Likewise.
	* tests/data/test-read-ctf/test-functions-declaration.abi:
	Likewise.
	* tests/data/test-read-ctf/test-linux-module.abi: Likewise.
	* tests/data/test-read-ctf/test-list-struct.abi: Likewise.
	* tests/data/test-read-ctf/test0.abi: Likewise.
	* tests/data/test-read-ctf/test0.hash.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/test3.so.abi: Likewise.
	* tests/data/test-read-ctf/test3.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test4.so.abi: Likewise.
	* tests/data/test-read-ctf/test4.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-ctf/test8.o.abi: Likewise.
	* tests/data/test-read-ctf/test9.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/PR28584/PR28584-smv.clang.o.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR29443-missing-xx.o.abi: Likewise.
	* tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.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-PR26568-1.o.abi: Likewise.
	* tests/data/test-read-dwarf/test-PR26568-2.o.abi: Likewise.
	* tests/data/test-read-dwarf/test-fallback.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-pointer-to-member-1.o.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/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/test0.xml: Likewise.
	* tests/data/test-read-write/test1.xml: Likewise.
	* tests/data/test-read-write/test10.xml: Likewise.
	* tests/data/test-read-write/test11.xml: Likewise.
	* tests/data/test-read-write/test12.xml: Likewise.
	* tests/data/test-read-write/test13.xml: Likewise.
	* tests/data/test-read-write/test14.xml: Likewise.
	* tests/data/test-read-write/test15.xml: Likewise.
	* tests/data/test-read-write/test16.xml: Likewise.
	* tests/data/test-read-write/test17.xml: Likewise.
	* tests/data/test-read-write/test18.xml: Likewise.
	* tests/data/test-read-write/test19.xml: Likewise.
	* tests/data/test-read-write/test2.xml: Likewise.
	* tests/data/test-read-write/test20.xml: Likewise.
	* tests/data/test-read-write/test21.xml: Likewise.
	* tests/data/test-read-write/test22.xml: Likewise.
	* tests/data/test-read-write/test23.xml: Likewise.
	* tests/data/test-read-write/test24.xml: Likewise.
	* tests/data/test-read-write/test25.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.
	* tests/data/test-read-write/test3.xml: Likewise.
	* tests/data/test-read-write/test4.xml: Likewise.
	* tests/data/test-read-write/test5.xml: Likewise.
	* tests/data/test-read-write/test6.xml: Likewise.
	* tests/data/test-read-write/test7.xml: Likewise.
	* tests/data/test-read-write/test8.xml: Likewise.
	* tests/data/test-read-write/test9.xml: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 17:15:43 +02:00
Dodji Seketeli
dc870a640b abipkgdiff: Make --verbose enable the library's logging
Up until now, --verbose would triggers logging inside the abipkgdiff
tool itself.  This patch allows it to see the logs of the library too.

	* tools/abipkgdiff.cc (set_generic_options): Make --verbose
	trigger the logs of the library.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 15:20:42 +02:00
Dodji Seketeli
ae57c22115 dwarf-reader: Do not fix ELF symbols for virtual destructors
There are cases in DWARF emitted by old producers where some member
function DIEs lack reference to the ELF symbol they relate to.  To
address that issue the DWARF reader sets some functions (with linkage
name and no ELF symbol) to the ELF symbol matching that linkage name.

We should not do that destructors however, because of false positives
and because it seems destructors are well handled even by the old
producers that I had access to.

This finishes to fix the self-comparison of the llvm-libs package of fc37.

	* src/abg-dwarf-reader.cc (finish_member_function_reading): Do not
	schedule virtual destructors for ELF symbol-related function
	fixup.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 15:09:18 +02:00
Dodji Seketeli
5e9896dd2e ctf-reader: Make logging more obvious
Prefix the logs of the CTF reader with "CTF Reader:" so that it is
obvious to see where the logs come from.

	* src/abg-ctf-reader.cc (reader::read_corpus): Prefix the logs
	with "CTF Reader".

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 15:09:09 +02:00
Dodji Seketeli
44ba857592 dwarf-reader: Fix support of suppression specifications
While looking at something else, I realized that when functions and
variables are to be dropped on the floor by a suppression
specification, there are time where the function is suppressed but not
dropped from the ABI corpus.  This is due to some thinkos in the DWARF
reader code.  Fixed thus.

	* src/abg-dwarf-reader.cc (function_is_suppressed)
	(variable_is_suppressed): Do not return too early when the
	function doesn't seem suppressed, yet.
	* tests/data/test-diff-suppr/test31-report-0.txt: Adjust.
	* tests/data/test-diff-suppr/test32-report-1.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 13:59:05 +02:00
Dodji Seketeli
b6e616cc92 btf-reader: Add logging methods
* src/abg-btf-reader.cc (reader::{do_log, show_stats}): Add new
	methods.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-29 13:58:54 +02:00
Dodji Seketeli
bcdb42782c dwarf-reader: Better support concrete instance functions DIEs
abidiff wrongly reports this change while comparing two binaries[1]:

  [C] 'function void g_cclosure_marshal_VOID__BOOLEAN(GClosure*, GValue*, guint, const GValue*, gpointer, gpointer)' at gmarshal.c:188:1 has some indirect sub-type changes:
    parameter 2 of type 'GValue*' changed:
      entity changed from 'GValue*' to 'typedef guint' at gtypes.h:61:1
      type size changed from 64 to 32 (in bits)
    parameter 3 of type 'typedef guint' changed:
      entity changed from 'typedef guint' to 'GValue*'
      type size changed from 32 to 64 (in bits)
    parameter 4 of type 'const GValue*' changed:
      in pointed to type 'const GValue' at gclosure.h:77:1:
        entity changed from 'const GValue' to 'typedef GClosure' at gclosure.h:77:1
        type size changed from 192 to 256 (in bits)
    parameter 6 of type 'typedef gpointer' changed:
      typedef name changed from gpointer to guint at gtypes.h:61:1
      underlying type 'void*' changed:
        entity changed from 'void*' to 'unsigned int'
        type size changed from 0 to 32 (in bits)
    parameter 7 of type 'const GValue*' was added
    parameter 8 of type 'typedef gpointer' was added
    parameter 9 of type 'typedef gpointer' was added

Let's look at the DWARF of the newer binary:

The abstract DIE for the g_cclosure_marshal_VOID__BOOLEAN is:
 [ 62c87]    subprogram           abbrev: 100
             external             (flag_present) yes
             name                 (strp) "g_cclosure_marshal_VOID__BOOLEAN"
             decl_file            (implicit_const) gmarshal.c (19)
             decl_line            (data1) 188
             decl_column          (implicit_const) 1
             prototyped           (flag_present) yes
             sibling              (ref_udata) [ 62d20]
 [ 62c8f]      formal_parameter     abbrev: 28
               name                 (GNU_strp_alt) "closure"
               decl_file            (data1) gmarshal.c (19)
               decl_line            (data1) 188
               decl_column          (data1) 49
               type                 (ref_addr) [   b10]
 [ 62c9b]      formal_parameter     abbrev: 28
               name                 (GNU_strp_alt) "return_value"
               decl_file            (data1) gmarshal.c (19)
               decl_line            (data1) 189
               decl_column          (data1) 49
               type                 (ref_addr) [   9db]
 [ 62ca7]      formal_parameter     abbrev: 28
               name                 (GNU_strp_alt) "n_param_values"
               decl_file            (data1) gmarshal.c (19)
               decl_line            (data1) 190
               decl_column          (data1) 49
               type                 (ref_addr) [   4e8]
 [ 62cb3]      formal_parameter     abbrev: 28
               name                 (GNU_strp_alt) "param_values"
               decl_file            (data1) gmarshal.c (19)
               decl_line            (data1) 191
               decl_column          (data1) 49
               type                 (ref_addr) [   9dd]
 [ 62cbf]      formal_parameter     abbrev: 28
               name                 (GNU_strp_alt) "invocation_hint"
               decl_file            (data1) gmarshal.c (19)
               decl_line            (data1) 192
               decl_column          (data1) 49
               type                 (ref_addr) [   3a0]
 [ 62ccb]      formal_parameter     abbrev: 28
               name                 (GNU_strp_alt) "marshal_data"
               decl_file            (data1) gmarshal.c (19)
               decl_line            (data1) 193
               decl_column          (data1) 49
               type                 (ref_addr) [   3a0]

Let's focus on its second parameter.  Its DIE is:
 [ 62c9b]      formal_parameter     abbrev: 28
               name                 (GNU_strp_alt) "return_value"
               decl_file            (data1) gmarshal.c (19)
               decl_line            (data1) 189
               decl_column          (data1) 49
               type                 (ref_addr) [   9db]

Of type:

 [   9db]    pointer_type         abbrev: 43
             byte_size            (implicit_const) 8
             type                 (ref_udata) [   9aa]
[...]
 [   9aa]    typedef              abbrev: 36
             name                 (GNU_strp_alt) "GValue"
             decl_file            (data1) gtype.h (9)
             decl_line            (data2) 431
             decl_column          (data1) 41
             type                 (ref_udata) [   9b6]

So it's a "GValue*" type.

Now, the concrete instance of that abstract DIE, which represent the
concrete function is:

 [ 12125]    subprogram           abbrev: 87
             abstract_origin      (ref_addr) [ 62c87]
             low_pc               (addr) +0x000000000001c450 <g_cclosure_marshal_VOID__BOOLEAN.part.0>
             high_pc              (udata) 100 (+0x000000000001c4b4)
             frame_base           (exprloc)
              [ 0] call_frame_cfa
             sibling              (ref_udata) [ 121de]
 [ 12138]      formal_parameter     abbrev: 58
               abstract_origin      (ref_addr) [ 62c8f]
               location             (sec_offset) location list [  c2dc]
               GNU_locviews         (sec_offset) location list [  c2d2]
 [ 12145]      formal_parameter     abbrev: 58
               abstract_origin      (ref_addr) [ 62cb3]
               location             (sec_offset) location list [  c317]
               GNU_locviews         (sec_offset) location list [  c30d]
 [ 12152]      formal_parameter     abbrev: 58
               abstract_origin      (ref_addr) [ 62ccb]
               location             (sec_offset) location list [  c354]
               GNU_locviews         (sec_offset) location list [  c348]
 [ 1218b]      formal_parameter     abbrev: 58
               abstract_origin      (ref_addr) [ 62cbf]
               location             (sec_offset) location list [  c3f9]
               GNU_locviews         (sec_offset) location list [  c3f7]
 [ 12198]      formal_parameter     abbrev: 58
               abstract_origin      (ref_addr) [ 62ca7]
               location             (sec_offset) location list [  c40a]
               GNU_locviews         (sec_offset) location list [  c408]
 [ 121a5]      formal_parameter     abbrev: 58
               abstract_origin      (ref_addr) [ 62c9b]
               location             (sec_offset) location list [  c41b]
               GNU_locviews         (sec_offset) location list [  c419]

Note how the formal parameters of that concrete instance are all in a
different order than the ones of the concrete instance ...

In this case, when reading the concrete instance, we need to get the
IR of the function from the abstract instance DIE and then only read
the potential complementary attributes from this concrete instance.

The DWARF reader mistakenly builds the IR for the function from the
concrete instance in this case, hence the wrong change reported down
the road.

This patch fixes that.

Note that artifacts coming from that bug, reported on IRC have been
added to the libabigail-tests.git test suite.

[1]: https://gitlab.com/freedesktop-sdk/freedesktop-sdk/-/merge_requests/21393#note_2077175107

	* src/abg-dwarf-reader.cc (build_ir_node_from_die):  If the DIE is
	a concrete instance of an abstract one, then get the IR from the
	abstract one as it has all the types right.
	* tests/data/test-annotate/test14-pr18893.so.abi: Adjust.
	* 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-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/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-28 17:52:02 +02:00
Dodji Seketeli
3c33437ddf ctf-reader: Enumerate dicts in the archive rather than using their name
ctf::reader::process_ctf_archive calls ctf_dict_open with the name of
the (parent) dictionary to open.  If that parent dictionary is set to
an unexpected name, then the call to ctf_dict_open fails.  This can
happen for instance when at link time, the name of the parent
dictionary is set to an arbitrary name using the
"ctf_link_set_memb_name_changer" function.

This patch enumerates the dictionaries of the archive to avoid having
to know the name of the parent dictionary.  The enumeration is done
using the ctf_archive_next function of libctf.

There is currently no binary with an unexpected dictionary name in the
test suite so this patch cannot be tested for that particular case.
I'd be glad to have such binaries added to the test suite.

In the mean time this patch has been tested successfully using "make
fullcheck" on the existing test suite.

	* src/abg-ctf-reader.cc (reader::process_ctf_archive):  Do not use
	ctf_dict_open to open the dictionary by name.  Rather, enumerate
	the dictionaries of the current archive by using ctf_archive_next
	just like what lookup_symbol_in_ctf_archive does.  Set the
	argument of the skip_parent parameter to "false" to ensure we get
	the parent dictionary.
	(lookup_symbol_in_ctf_archive): Clean this up to properly
	initialize the parameters and to document the arguments to the
	parameters of ctf_archive_next.  Use nullptr instead of NULL.
	* tests/data/test-diff-pkg-ctf/test-rpm-report-1.txt: Adjust.
	* tests/data/test-diff-pkg-ctf/test-rpm-report-2.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-20 19:37:56 +02:00
Dodji Seketeli
0278493b72 ir: Handle ptr to fn type member with empty void return type
If a pointer to member type points to a function type that has an
empty return type, sometimes that can lead to a crash.  This patch
considers that the empty return type is a void type.

	* src/abg-ir.cc (add_outer_ptr_to_mbr_type_expr): If the function
	type has no return type, consider it as void type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-16 20:44:21 +02:00
Dodji Seketeli
2e1dbb2a6f reader: Avoid empty return type node for a function type IR
Sometimes, the function type IR can have an empty node as return type,
to represent void.  This can wreak havoc on some part of the code that
don't expect that.  This patch uses a proper void type node for that
instead.

	* src/abg-reader.cc (build_function_type): If the return type node
	is empty, use a void type node.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-16 20:43:46 +02:00
Dodji Seketeli
798c013de0 ir: Don't cache internal name of non-canonicalized function types
When a function type is not yet canonicalized, do not cache its name,
otherwise, the name can capture the state of the function in a too
early state.

	* src/abg-ir.cc (function_type::get_cached_name): Do not cache
	internal name for non-canonicalized function types.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-16 20:39:56 +02:00
Dodji Seketeli
dcce841c54 ir: Improve legibility of set_member_function_is_virtual
* src/abg-ir.cc (set_member_function_is_virtual): Remove
	useless white space and use clearer helper function.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-16 20:38:44 +02:00
Dodji Seketeli
7de9d769bc abidw: Make generic options like --verbose work with the ABIXML front-end
* tools/abidw.cc (set_generic_options): Take a fe_iface in
	parameter, not an elf_based_reader.
	(perform_self_comparison): Call set_generic_options.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-14 14:24:27 +02:00
Dodji Seketeli
7a62ac1526 reader: Fix building of reference type
This patch ensures that the built reference type IR node is always associated
with the type-id used in the ABIXML.

	* src/abg-reader.cc (build_reference_type_def): Remove unnecessary
	condition.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-14 14:24:22 +02:00
Dodji Seketeli
de03c87c50 reader: Avoid crashing on empty scopes in reader::push_decl_to_scope
When abixml::reader::push_decl_to_scope gets a nullptr scope, it can
sometimes abort.  Fixed thus.

	* src/abg-reader.cc (reader::push_decl_to_scope): It's only if
	there is a non-nil scope that the assert can be reached.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2024-08-14 14:24:17 +02:00