]> sourceware.org Git - libabigail.git/log
libabigail.git
3 months agoir: Handle ptr to fn type member with empty void return type users/dodji/merge users/dodji/try-merge
Dodji Seketeli [Fri, 16 Aug 2024 17:02:46 +0000 (19:02 +0200)]
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>
3 months agoreader: Avoid empty return type node for a function type IR
Dodji Seketeli [Fri, 16 Aug 2024 12:48:39 +0000 (14:48 +0200)]
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>
3 months agoir: Don't cache internal name of non-canonicalized function types
Dodji Seketeli [Fri, 16 Aug 2024 12:27:01 +0000 (14:27 +0200)]
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>
3 months agoir: Improve legibility of set_member_function_is_virtual
Dodji Seketeli [Fri, 16 Aug 2024 11:54:57 +0000 (13:54 +0200)]
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>
4 months agoabidw: Make generic options like --verbose work with the ABIXML front-end
Dodji Seketeli [Tue, 6 Aug 2024 15:47:19 +0000 (17:47 +0200)]
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>
4 months agoreader: Fix building of reference type
Dodji Seketeli [Tue, 13 Aug 2024 15:37:53 +0000 (17:37 +0200)]
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>
4 months agoreader: Avoid crashing on empty scopes in reader::push_decl_to_scope
Dodji Seketeli [Tue, 13 Aug 2024 14:33:10 +0000 (16:33 +0200)]
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>
4 months agoir: Fix comment for translation_unit::get_global_scope
Dodji Seketeli [Tue, 6 Aug 2024 08:08:25 +0000 (10:08 +0200)]
ir: Fix comment for translation_unit::get_global_scope

* src/abg-ir.cc (translation_unit::get_global_scope): Fix comment.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir: Speed up enum comparison
Dodji Seketeli [Tue, 6 Aug 2024 08:03:09 +0000 (10:03 +0200)]
ir: Speed up enum comparison

When two enums are naively equal, comparing then member-wise should be
fast.  This patch does just that.  This speeds up things a lot, in the
context of self-comparison and type canonicalization (from DWARF) when
there are huge enums in the binary.

* src/abg-ir.cc (equals): In the overload for enums, compare
enumerators naively for the case both enums are naively equal.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir: Support comparing a class_decl against a class_or_union
Dodji Seketeli [Mon, 5 Aug 2024 15:47:01 +0000 (17:47 +0200)]
ir: Support comparing a class_decl against a class_or_union

When a class_decl is compared against a class_or_union type using
class_decl::operator==, that operator systematically fails.  This
patch fixes that by comparing the common parts between the two
objects.

* src/abg-ir.cc (class_decl::operator==): Support comparing
against a class_or_union.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir: Support canonical type adjustments for decl-only class types
Dodji Seketeli [Mon, 5 Aug 2024 14:32:45 +0000 (16:32 +0200)]
ir: Support canonical type adjustments for decl-only class types

When a decl-only class 'D' type (which has an associated class type) is
canonicalized and its canonical type is being adjusted to make sure it
contains all the member functions of 'D', the member functions are not
being taken into account.  Fixed thus.

* src/abg-ir.cc (maybe_adjust_canonical_type): Look through
decl-only classes to get their definition.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir: Make odr_is_relevant support support artifacts with no TU set yet
Dodji Seketeli [Thu, 1 Aug 2024 17:02:24 +0000 (19:02 +0200)]
ir: Make odr_is_relevant support support artifacts with no TU set yet

* src/abg-ir.cc (odr_is_relevant): Consider that an artifact with
no associated TU is not relevant for ODR considerations.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir: add_decl_to_scope shouldn't abort on nullptr scopes
Dodji Seketeli [Thu, 1 Aug 2024 16:52:43 +0000 (18:52 +0200)]
ir: add_decl_to_scope shouldn't abort on nullptr scopes

* src/abg-ir.cc (add_decl_to_scope): Do not abort on an empty
scope.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir: Fix getting the translation unit for an ABI artifact
Dodji Seketeli [Thu, 1 Aug 2024 11:22:34 +0000 (13:22 +0200)]
ir: Fix getting the translation unit for an ABI artifact

Sometimes when the current translation unit is not yet set for a given
artifact, we can infer it by getting the translation unit of the scope
of the artifact.  This patch performs that inference when the
translation unit is not yet set for the current artifact.

* include/abg-fwd.h (get_translation_unit): Take a
type_or_decl_base parameter, not a decl_base.
* src/abg-ir.cc (get_translation_unit): Likewise.  If no
translation has yet been associated with the ABI artifact, get it
from its scope.
(type_or_decl_base::get_corpus): Use the new get_translation_unit.
(maybe_set_translation_unit): Assert that the translation unit is
non-nil.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoUse smart pointers for variables exported from the ABI corpus
Dodji Seketeli [Wed, 31 Jul 2024 10:12:43 +0000 (12:12 +0200)]
Use smart pointers for variables exported from the ABI corpus

It turned out that for some applications using the library, being able
to share the variables returned by
libabigail::ir::corpus::lookup_variable is useful.  This patch changes
the API to use shared pointer for variables exported from the ABI
corpus.  For the sake of consistency, we should do the same for
function decls, but given the churn, I thought I'd do it for variables
first and see the impact.  If it's OK then I'll do it for function
decls too.

* include/abg-comparison.h (string_var_ptr_map): Use a
var_decl_sptr rather than a var_decl*.
* include/abg-corpus.h (corpus::{variable, variables_set}):
Likewise.
(corpus::lookup_variable): Return a var_decl_sptr not a var_decl*.
(corpus::exported_decls_builder::maybe_add_var_to_exported_vars):
Take a var_decl_sptr, not a var_decl*.
* include/abg-fe-iface.h
(fe_iface::add_var_to_exported_or_undefined_decls): Likewise.
* include/abg-ir.h (istring_var_decl_ptr_map_type): Use a
var_decl_sptr rather than a var_decl*.
* src/abg-btf-reader.cc (reader::build_ir_node_from_btf_type):
Adjust call to add_var_to_exported_or_undefined_decls.
* src/abg-comparison-priv.h (var_comp::operator()()): Add a new
overload for var_decl_sptr.
(corpus_diff::priv::{deleted_variable_is_suppressed,
deleted_variable_is_suppressed}): Take a var_decl_sptr not a
var_decl*.
(sort_string_var_ptr_map): Take ...
* src/abg-comparison.cc (sort_string_var_ptr_map): ... a
vector<var_decl_sptr> rather than a vector<var_decl*>.
(corpus_diff::priv::ensure_lookup_tables_populated): Adjust.
(variable_is_suppressed): Likewise.
(corpus_diff::priv::{deleted_variable_is_suppressed,
added_variable_is_suppressed}): Likewise.
* src/abg-corpus-priv.h (str_var_ptr_map_type)
(istr_var_ptr_map_type): Use a var_decl_sptr rather than a
var_decl*.
(corpus::exported_decls_builder::priv::{add_var_to_map,
keep_wrt_id_of_vars_to_keep, keep_wrt_regex_of_vars_to_suppress,
keep_wrt_regex_of_vars_to_keep}): Likewise.
(corpus::exported_decls_builder::priv::vars): Likewise.
* src/abg-corpus.cc
(corpus::exported_decls_builder::maybe_add_var_to_exported_vars):
Likewise.
(var_comp::operator()()): Add an overload for var_decl_sptr.
(corpus::lookup_variable): Return var_decl_sptr rather than
var_decl*.
* src/abg-ctf-reader.cc (reader::process_ctf_archive): Adjust.
* src/abg-dwarf-reader.cc (build_ir_node_from_die): Adjust.
* src/abg-fe-iface.cc
(fe_iface::add_var_to_exported_or_undefined_decls): Take a
var_decl_sptr rather than a var_decl*.
* src/abg-reader.cc (build_class_decl, handle_var_decl): Adjust.
* src/abg-writer.cc (write_translation_unit): Likewise.
* tools/abicompat.cc (var_change::decl, var_change::var_change):
Likewise.
(compare_expected_against_provided_variables): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoconfigure.ac: Fix typo triggered when --enable-big-tests is used
Dodji Seketeli [Wed, 7 Aug 2024 16:37:11 +0000 (18:37 +0200)]
configure.ac: Fix typo triggered when --enable-big-tests is used

* configure.ac: It's "cd $ac_abs_top_srcdir/big-tests", not
"cd ac_abs_top_srcdir/big-tests"

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoconfigure: Support the optional 'big-tests' sub-directory
Dodji Seketeli [Thu, 4 Jul 2024 12:19:08 +0000 (14:19 +0200)]
configure: Support the optional 'big-tests' sub-directory

If the 'big-tests' sub-directory (or a symbolic link to it) is present
then this patch configures it.

By default, the patch defines a new git sub-module into the
'big-tests' sub-directory.  That git sub-module is the repository
git://sourceware.org/git/libabigail-tests.  Users can now add the
--recurse-submodules option to git clone when they clone
git://sourceware.org/git/libabigail, so that it clones git big-tests
submodule as well.

The patch adds a new 'big-tests' target (to the top-most Makefile.am)
which runs "make check" in the big-tests sub-directory.

The patch also adds a new 'full-check' target that runs targets check,
check-self-compare and big-tests.

        * Makefile.am: Add big-tests,clean-big-tests and full-check
targets.
        * configure.ac: Add an --enable-big-tests option.  For now, this
option is mandatory to handle the optional 'big-tests' support.
If the --enable-big-tests option is provided and if the
'big-tests' sub-directory is present, configure the big-tests/
sub-package.
* .gitmodules: New sub-module configuration to get
git://sourceware.org/git/libabigail-tests and stick into ...
* big-tests: ... this directory as a sub-module.
* CONTRIBUTING: Update this to explain how to get the Big Tests
going.
* tests/Makefile.am: Update the test summary for the
check-self-compare target.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoabidw: Support the --abidiff option for Linux Kernel trees
Dodji Seketeli [Tue, 9 Jul 2024 15:01:01 +0000 (17:01 +0200)]
abidw: Support the --abidiff option for Linux Kernel trees

It turned out abidw --abidiff (self-comparison) doesn't work when
analyzing a Linux Kernel tree.  In other words, abidw cannot
self-compare a Linux Kernel tree.  Embarrassing.  Fixed thus.

* include/abg-corpus.h (is_corpus_group): Declare ...
* src/abg-corpus.cc (is_corpus_group): ... new function.
* src/abg-ctf-reader.cc (create_reader): Support --debug-abidiff
when the package is configured with --enable-debug-self-comparison.
* tools/abidw.cc (load_corpus_and_write_abixml): Factorize self
comparison code out into ...
(perform_self_comparison): ... this.
(load_kernel_corpus_group_and_write_abixml): Use the new
perform_self_comparison to perform self comparison when the
--abidiff option is provided.  Also, support --debug-abidiff when
the package is configured with --enable-debug-self-comparison.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir,comparison,default-reporter: Consider sub-ranges in array diffs
Dodji Seketeli [Tue, 9 Jul 2024 12:54:45 +0000 (14:54 +0200)]
ir,comparison,default-reporter: Consider sub-ranges in array diffs

It appears that the comparison engine does not take changes in the
underlying types of sub-ranges into account when looking for sub-range
changes.

This patch fixes that issue.

Then the patch amends the diff model of array_diff to make it take
into account sub-range diffs as children diff nodes.  Then it updates
redundancy propagation to make sure changes to sub-ranges are always
reported even when they are redundant.  The patch filters out harmless
name changes to integral types, by default.

* include/abg-comparison.h (array_diff::array_diff): Take a vector
of sub-range diffs as children diff nodes.
(array_diff::{subrange_diffs, any_subrange_diff_to_be_reported}):
Declare new methods.
(is_anonymous_subrange_diff): Declare new function.
* src/abg-comp-filter.cc (integral_type_has_harmless_name_change):
Define new function.
(has_harmless_name_change): Use the new
integral_type_has_harmless_name_change.
* src/abg-comparison-priv.h (array_diff::priv::subrange_diffs_):
Define new data member.
* src/abg-comparison.cc (is_anonymous_class_or_union_diff): Fix
comment.
(is_anonymous_subrange_diff): Define new function.
(array_diff::chain_into_hierarchy): Append sub-range diffs as
children nodes of the array_diff node.
(array_diff::array_diff): Take a vector of sub-range diffs as
children diff nodes.
(array_diff::{subrange_diffs, any_subrange_diff_to_be_reported}):
Define new methods.
(array_diff::has_changes): Take sub-range diffs into account.
(compute_diff): In the overload for array_type_def, compute diffs
for sub-ranges as part of the diff for array_type_defs.
(leaf_diff_node_marker_visitor::visit_begin): Do not consider an
anonymous sub-range diff node as being a leaf diff node to report
about.
(redundancy_marking_visitor::visit_end): Report all sub-range diff
nodes changes; do not propagate their (potential) redundancy to
their array_diff node parent.
* src/abg-default-reporter.cc (default_reporter::report): In the
overload for array_diff, if there is a sub-range change to be
reported, then report it.
* src/abg-ir-priv.h (real_type::base_type): Add SIZE_BASE_TYPE,
SSIZE_BASE_TYPE, BIT_SIZE_BASE_TYPE, SBIT_SIZE_BASE_TYPE,
ARRAY_SIZE_BASE_TYPE enumerators to this enum.
* src/abg-ir.cc (parse_base_real_type): Support parsing real type
names that are __ARRAY_SIZE_TYPE__, sizetype, ssizetype,
bitsizetype and sbitsizetype.
(real_type::to_string): Support IZE_BASE_TYPE, SSIZE_BASE_TYPE,
BIT_SIZE_BASE_TYPE, SBIT_SIZE_BASE_TYPE and ARRAY_SIZE_BASE_TYPE
enumerators.
(equals): In the overload for array_type_def::subrange_type,
compare the underlying types of the sub-ranged.  In the overload
for array_type_def, consider sub-range changes mismatch as a local
non-type change.  This is so that changes to sub-ranges don't get
filtered out because changes to element types are redundant.
* src/abg-reporter-priv.cc (represent): In the overload for
subrange_diff, clean up reporting of change of bound values.
Also, add reports of changes from non-finite to finite size.
* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-1.txt:
Adjust.
* Tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-2.txt:
Likewise.
* tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-1.txt:
Likewise.
* tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-2.txt:
Likewise.
* tests/data/test-abidiff-exit/test-allow-type-array-v0--v1-report-1.txt:
Likewise.
* tests/data/test-abidiff-exit/test-allow-type-array-v0--v3-report-1.txt:
Likewise.
* tests/data/test-abidiff/test-PR27985-report.txt: Likewise.
* tests/data/test-diff-dwarf/test10-report.txt: Likewise.
* tests/data/test-diff-dwarf/test11-report.txt: Likewise.
* tests/data/test-diff-dwarf/test35-pr19173-libfoo-long-clang-report-0.txt:
Likewise.
* tests/data/test-diff-dwarf/test35-pr19173-libfoo-long-gcc-report-0.txt:
Likewise.
* tests/data/test-diff-filter/PR24430-fold-qualified-array-report-0.txt:
Likewise.
* tests/data/test-diff-filter/test-PR29811-0-report-1.txt:
Likewise.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
Likewise.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt:
Likewise.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt:
Likewise.
* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
Likewise.
* tests/data/test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm--libICE-1.0.9-2.el7.x86_64.rpm-report-0.txt:
Likewise.
* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
Likewise.
* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
Likewise.
* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
Likewise.
* tests/data/test-diff-suppr/test-has-data-member-inserted-at-1-report-1.txt:
Likewise.
* tests/data/test-diff-suppr/test-has-strict-flexible-array-data-member-conversion-report-2.txt:
Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir: Rename integral_type into real_type
Dodji Seketeli [Mon, 8 Jul 2024 13:56:03 +0000 (15:56 +0200)]
ir: Rename integral_type into real_type

It turns out what we call integral_type in the libabigail IR is
actually a real_type because it includes real types (float and
double).  This patch rights that wrong.

* include/abg-fwd.h (is_real_type): Declare new function.
* src/abg-ctf-reader.cc (process_ctf_base_type): Adjust.
* src/abg-dwarf-reader.cc (die_qualified_type_name)
(build_type_decl): Adjust.
* src/abg-ir-priv.h (class real_type): Rename class integral_type
into this.
* src/abg-ir.cc (get_internal_real_type_name, operator|)
(operator&, operator~, operator|=, operator&=)
(parse_real_type_modifier, parse_base_real_type, parse_real_type)
(real_type::{real_type, get_base_type, get_modifiers,
set_modifiers, to_string, operator string()}):
s/integral_type/real_type.
(type_decl::{type_decl, get_qualified_name,
get_pretty_representation}): Adjust.
(is_real_type): Define new function.
(is_integral_type): Use the new is_real_type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir: Don't strip typedefs from parms and return type when comparing fns
Dodji Seketeli [Mon, 8 Jul 2024 15:12:06 +0000 (17:12 +0200)]
ir: Don't strip typedefs from parms and return type when comparing fns

As we are now sorting types so that they are
always compared in the same order during canonicalization,
irrespective of the front-end, I believe stripping typedefs from
function parameteres and return types during comparison is no more
necessary.  And also, that removes so spurious changes reports.

* src/abg-ir.cc (equals): In the overloads from function_type and
function_decl::parameter, do not strip typedefs off of types
becore comparing them.
* tests/data/test-abidiff-exit/PR30329/PR30329-report-1.txt:
Adjust.
* 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:
Adjust.
* tests/data/test-abidiff-exit/PR31513/reported/PR31513-reported-report-2.txt:
Adjust.
* tests/data/test-annotate/test14-pr18893.so.abi: Adjust.
* tests/data/test-annotate/test15-pr18892.so.abi: Adjust.
* tests/data/test-annotate/test17-pr19027.so.abi: Adjust.
* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
Adjust.
* tests/data/test-diff-dwarf/test2-report.txt: Adjust.
* tests/data/test-diff-filter/test3-report.txt: Adjust.
* tests/data/test-diff-pkg-ctf/gmp-6.x.x86_64-report-0.txt:
Adjust.
* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Adjust.
* tests/data/test-read-dwarf/test-libandroid.so.abi: Adjust.
* tests/data/test-read-dwarf/test14-pr18893.so.abi: Adjust.
* tests/data/test-read-dwarf/test15-pr18892.so.abi: Adjust.
* tests/data/test-read-dwarf/test17-pr19027.so.abi: Adjust.
* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
Adjust.
* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoreader: Fix building of variadic parameter type
Dodji Seketeli [Fri, 5 Jul 2024 11:33:57 +0000 (13:33 +0200)]
reader: Fix building of variadic parameter type

variadic parameter type is not added to its proper scope, leading to
issues down the road.  Fixed thus.

* src/abg-ir-priv.h (type_topo_comp::operator()): Do not compare
types using their location anymore.  It's unnecessary (now that
types are sorted before canonicalization) and it wreaks havoc with
the new properly constructed variadic parameter types.
* src/abg-reader.cc (build_ir_node_for_variadic_parameter_type):
Define new function.  Add variadic parameter type to the global
scope of the current translation unit.
(build_function_parameter, build_type_decl): Use the new
build_ir_node_for_variadic_parameter_type.
* tests/data/test-read-write/test17.xml: Adjust.
* tests/data/test-read-write/test19.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/test25.xml: Likewise.
* tests/data/test-read-write/test26.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>
4 months agoreader: Fix building of void and void pointer types
Dodji Seketeli [Fri, 5 Jul 2024 11:31:52 +0000 (13:31 +0200)]
reader: Fix building of void and void pointer types

build_ir_node_for_void_pointer_type and build_ir_node_for_void_type
get the type IR from the environment, add it to the global scope of
the current translation unit and schedule it for type
canonicalization.

This patch change the code of these functions so that the adding to
the scope and the canonicalization are done only on the first
invocation of these functions.  Subsequent invocations just return the
type IR.

Otherwise, subsequent invocations were unnecessarily trying to add the
type IR to yet another global scope and were trying to canonicalize it
again.

* src/abg-reader.cc (build_ir_node_for_void_pointer_type)
(build_ir_node_for_void_type): Add the type to its scope and
schedule it for canonicalization just once.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoreader: Simplify logic of get_or_read_and_add_translation_unit
Dodji Seketeli [Fri, 5 Jul 2024 11:25:32 +0000 (13:25 +0200)]
reader: Simplify logic of get_or_read_and_add_translation_unit

* src/abg-reader.cc (get_or_read_and_add_translation_unit):
Simplify logic.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoreader: Simplify type canonicalization invocation
Dodji Seketeli [Fri, 5 Jul 2024 09:27:33 +0000 (11:27 +0200)]
reader: Simplify type canonicalization invocation

The ABIXML reader currently canonicalizes some (simple) types directly
and schedules canonicalization of other types for after the corpus has
been built.  This dual mode of operation was used back then when
ABIXML types were not aggressively de-duplicated as they are now.
Today, type canonicalization needs to happen in the same way for all
readers.

This patch thus schedules type canonicalization for after the creation
of the corpus, in the ABIXML reader.

* src/abg-reader.cc (reader::maybe_canonicalize_type): Remove.
(reader::schedule_type_for_canonicalization): Do not schedule
nullptr types for canonicalization.
(reader::perform_type_canonicalization): Rename
perform_late_type_canonicalizing into this.
(reader::{read_corpus, build_or_get_type_decl}): Adjust call to
maybe_canonicalize_type into schedule_type_for_canonicalization.
(read_translation_unit_from_file)
(read_translation_unit_from_buffer, read_translation_unit)
(build_function_decl, build_ir_node_for_void_type)
(build_array_type_def, build_ir_node_for_void_pointer_type)
(build_class_decl, build_union_decl)
(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):
Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoreader: Fix corpus group reading
Dodji Seketeli [Fri, 5 Jul 2024 09:13:14 +0000 (11:13 +0200)]
reader: Fix corpus group reading

Reading of corpus group is broken in the ABIXML reader.  Only the main
corpus is read and then, abixml::reader::read_corpus_group_from_input
fails to read subsequent corpora.

This patch fixes abixml::reader::read_corpus_group_from_input and
makes it call a new abixml::reader::initialize function, much like
what the ELF based readers are doing.

* src/abg-fe-iface.cc (fe_iface::priv::initialize): Do not clear
the corpus group upon initialization.
* src/abg-reader.cc (reader::initialize): Define new function.
Make it call fe_iface::initialize.
(reader::clear_per_corpus_data): Remove.
(reader::read_corpus): Remove call to clear_per_corpus_data.
(reader::read_corpus_group_from_input): After calling
reader::read_corpus and adding the resulting corpus to the group,
get the next sibling XML element node.  If it's an "abi-corpus"
node then re-initialize the reader by invoking the new
reader::initialize and move on to read it by invoking
reader::read_corpus again.
* tests/data/test-diff-suppr/test45-abi-report-1.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoctf-reader: Fix analyzing single kernel binaries
Dodji Seketeli [Wed, 10 Jul 2024 15:14:20 +0000 (17:14 +0200)]
ctf-reader: Fix analyzing single kernel binaries

Analyzing a single kernel binary has been broken for a long time, it
seems.  For the record, I mean this:

    $ abidw --ctf vmlinux > vmlinux.ctf.abi

Doesn't work.

This patch fixes ctf::reader::slurp_elf_info to make it not crash on
binaries that have no CTF sections because there is a .ctfa file in
the same directory.

Also, it fixes ctf::reader::read_corpus to support loading the CTF
archive for individual kernel binaries and not just for entire trees
(corpus groups).  In the case of individual kernel binaries, the
archive can be built from the CTF sections of the binary.

* src/abg-ctf-reader.cc (reader::slurp_elf_info): Do not crash on
a kernel binary that has no CTF section because the CTF
information is in a .ctfa file in the same directory.
(reader::read_corpus): Support loading a CTF archive for a single
kernel binary.  Also, support loading the CTF archive from the CTF
sections in the binary itself not necessarily from a .ctfa file in
the same directory.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoctf-reader: During re-initialization, only clear canonicalize-able types
Dodji Seketeli [Fri, 28 Jun 2024 16:33:04 +0000 (18:33 +0200)]
ctf-reader: During re-initialization, only clear canonicalize-able types

The patch
https://sourceware.org/git/?p=libabigail.git;a=commit;h=666555665cc4fcfc8ae19661c489822e0df00ae3
introduced a mistake: It frees the CTF archive object during the
re-initialization of the reader between each binary (kernel or
module).  The archive contains CTF type information for a kernel and
all its modules.  So it should be kept around until all those binaries
are analyzed.  Instead, that patch frees the CTF archive object after
handling each binary.  Oops.

This patch fixes that problem by free-ing the CTF archive only when
the reader itself is freed, presumably, after analyzing all binaries.

Similarly, the type map maintained by the reader contains types for
the kernel and all its modules.  So it should not be freed at
re-initialization time.  Rather, what should be freed is only the
types that are to be canonicalized at the end of processing of a given
binary.  So the patch makes the reader maintain types to be
canonicalized in a vector and clears that vector at each
re-initialization.

At re-initialization time, the patch also avoids resetting the corpus
group that the current reader feeds.

* src/abg-ctf-reader.cc (reader::types_to_canonicalize): Add data
member.
(reader::add_type): Add the new type to the vector of types to be
canonicalized.  Update comment.
(reader::canonicalize_all_types): Now that the reader maintains
the vector of types to be canonicalized, just pass that vector to
canonicalize_types.  reader::types_map contains all the types that
have been created in all the binaries processed by this reader so
far.  Many of these types have already been canonicalized at the
end of the analysis of binaries that have already been processed.
Only the types created during the processing of the current binary
have not yet be canonicalized and reader::types_to_canonicalize is
where they are maintained.  So reader::types_map should be left
alone by this function.
(reader::initialize): Do not close the CTF archive here.  Do not
clear reader::{types_map, corpus_group} either.
(reader::read_corpus): Use nullptr, not NULL.  Make sure to not
re-open an archive that has already been opened.
(reader::~reader): Mark a closed archive.  This is more cosmetic
than anything else.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoctf-reader: Do not set data member offsets for unions
Dodji Seketeli [Mon, 15 Jul 2024 14:16:24 +0000 (16:16 +0200)]
ctf-reader: Do not set data member offsets for unions

All union data members should have an offset set to 0.  It turns out
the CTF reader unnecessarily sets the data member offset.  This patch
fixes that.

* src/abg-ctf-reader.cc (process_ctf_sou_members): Do not set any
union data member offset.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agocorpus: Support adding translation units with empty path
Dodji Seketeli [Tue, 9 Jul 2024 14:44:00 +0000 (16:44 +0200)]
corpus: Support adding translation units with empty path

The CTF front-end produces an artificial translation unit with an
empty path for all the types in a given ABI corpus.  Adding such a
translation unit to its corpus is conditioned on it having a non-empty
path.  Oops.  Fixed thus.

* src/abg-corpus.cc (corpus::add): Do not require that the path of
the translation unit be non-empty.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agotools-utils,btf-reader: Take modules into account for corpus group
Dodji Seketeli [Mon, 15 Jul 2024 07:48:10 +0000 (09:48 +0200)]
tools-utils,btf-reader: Take modules into account for corpus group

It turns out the BTF front-end won't take kernel modules into account
when analyzing a linux kernel build tree.

This is because it doesn't support split and base BTF objects.

Please note that the BTF API is not yet documented in
https://docs.kernel.org/bpf/btf.html, so my understanding of how it
works comes the source code of the bpftool program available at
https://github.com/libbpf/bpftool and https://github.com/libbpf/libbpf.

When analyzing the vmlinux binary, the btf__parse function returns a
"base BTF object" which contains the type information contained in the
.BTF section of that binary.  The memory of the BTF types describing
the types of vmlinux lives in the base BTF object.  So the base BTF
object must be kept around for the entire time of the analysis of the
Linux kernel tree (vmlinux + modules).

When analyzing a kernel module however, it's the btf__parse_split
function that is used.  That function takes into parameter the "base
BTF object" representing the type information of the corresponding
vmlinux binary and returns a "split BTF object" which contains the
type information contained in the .BTF section of the kernel module.
Please note that the split BTF object does reference the base BTF
object as well.  The memory of the BTF types describing the types the
kernel module lives in the split BTF object.  Because some types and
decls might be exported by a kernel module and used by another one,
the memory of a given split BTF object might be needed to be kept
alive for the entire time of the analysis of the Linux kernel tree as
well.

It's this base/split model of BTF that is not supported by the BTF
front-end.

This patch introduces support for that model.

At any point in time, the BTF front-end now has one handle to the base
BTF object and one handle to the current split BTF object if we are
looking at kernel module.  The base and split BTF objects are kept
around for the entire lifetime of the front-end.

For a given binary, each type is identified by a type ID.  The
validity of a given type ID is effective only for that binary.  The
same type ID in another binary might designate another type.  So
rather than maintaining a map that associates a type ID with a libabigail
IR artifact, the front-end now maintains a map that associates a
*type* with libabigail IR artifact.

With this changes, abidw can now analyze and emit the ABIXML for a
linux kernel tree in 28 seconds, using BTF.  It can self-compare a
kernel tree in 36 seconds.

* src/abg-btf-reader.cc (btf_type_to_abi_artifact_map_type):
Rename btf_type_id_to_abi_artifact_map_type into this.  Make it
associate a btf_type* to a libabigail IR, rather than a type ID to
a libabigail IR.
(reader::{base_btf_handle_, base_btf_file_name_,
split_btf_handle_, split_btf_file_name_, split_btfs_to_free_}):
Define new data members.
(reader::{btf_handle_}): Remove.
(reader::base_btf_handle): Renamed btf_handle into this.  Create
the BTF object using btf__parse.  Store the name of the binary
into reader::base_btf_file_name_.
(reader::read_split_btf): Define new member function.
(reader::btf_handle): This is new code for an existing member
function name.  Return the current split BTF object handle if
applicable, otherwise create the base BTF object handle.
(reader::btf_type_to_artifacts_): Renamed
btf_type_id_to_artifacts into this.
(reader::associate_artifact_to_btf_type): Renamed
associate_artifact_to_btf_type_id into this.
(reader::schedule_type_for_canonicalization): Do not schedule a
type that has already been canonicalized.
(reader::nr_btf_types): Take a BTF* parameter.
(reader::~reader): Free all the allocated split BTF objects.
(reader::read_debug_info_into_corpus): If we are looking at a
split BTF, then set the first type ID as the one right after the
last type ID of the base BTF.
(reader::build_ir_node_from_btf_type): Clean-up the logic for
building type void type.
(reader::{build_ir_node_for_void_type,
build_ir_node_for_void_pointer_type,
build_ir_node_for_variadic_parameter_type,
build_enum_underlying_type, build_array_type}): Schedule type for
canonicalization at the end of the IR construction, not right
away.
* src/abg-tools-utils.cc (create_best_elf_based_reader): Pass
show_all_types and linux_kernel_mode arguments to
btf::create_reader.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoelf-based-reader: Clean up logic of elf_based_reader::read_and_add_corpus_to_group
Dodji Seketeli [Tue, 9 Jul 2024 14:55:18 +0000 (16:55 +0200)]
elf-based-reader: Clean up logic of elf_based_reader::read_and_add_corpus_to_group

While looking at something else, I noticed the logic of
elf_based_reader::read_and_add_corpus_to_group wasn't clear.  The
corpus should be read (thus created) first, then added to the reader.
Fixed thus.

* src/abg-elf-based-reader.cc
(elf_based_reader::read_and_add_corpus_to_group): Fix logic.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
4 months agoir: Fix a potential crash in canonicalize_types
Dodji Seketeli [Tue, 9 Jul 2024 14:57:26 +0000 (16:57 +0200)]
ir: Fix a potential crash in canonicalize_types

I noticed crashes in canonicalize_types when it deals with nullptr
types.  Fixed thus.

* src/abg-ir-priv.h (canonicalize_types): Avoid crashing when
de-referencing an iterator to a nullptr type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
5 months agoconfigure.ac: improve fts checks
Ross Burton [Wed, 10 Jul 2024 10:38:05 +0000 (11:38 +0100)]
configure.ac: improve fts checks

The current code checks explicitly for musl and if so uses pkg-config to
find fts-standalone. This is suboptimal because musl may not be the only
libc to need a standalone fts implementation, and fts-standalone is an
old gentoo-specific name[1] so libabigail won't build on any other system
against musl.

Instead, use AC_SEARCH_LIBS to look for fts_open in libc then libfts. Do
this before the check for behaviour just in case someone has a standalone
and broken implementation.  I assume that the standalone fts is installed
on the standard search path, which should be a fair assumption.

As we're not using pkg-config anymore the required link flags are now in
LIBS, so remove all instances of FTS_CFLAGS and FTS_LIBS.

[1] https://gitweb.gentoo.org/repo/gentoo.git/commit/sys-libs/fts-standalone?id=a403fe6c61d1aaeecd58d521f3def2f6d3513449

* configure.ac: Use AC_SEARCH_LIBS to look for fts_open in libc
and in libfts if necessary.  Remove the use of FTS_LIBS which is
now unnecessary.
* src/Makefile.am: Do not use FTF_LIBS as it's now unnecessary.
* tools/Makefile.am: Likewise.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
5 months agobtf-reader: Add missing data members reset to reader::initialize
Dodji Seketeli [Fri, 21 Jun 2024 15:04:40 +0000 (17:04 +0200)]
btf-reader: Add missing data members reset to reader::initialize

btf::reader::initialize forgets to reset a few data members used
during binary type information loading.  This resetting is key to get
the reader ready for being re-used to load a new binary, like a kernel
module.  Otherwise, the working set just keeps growing unnecessarily.

* src/abg-btf-reader.cc (btf::reader::initialize): Clear
types_to_canonicalize_, btf_type_id_to_artifacts_ and cur_tu_.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
5 months agodwarf-reader: Fix reader::initialize to clear per corpus data
Dodji Seketeli [Fri, 21 Jun 2024 14:49:29 +0000 (16:49 +0200)]
dwarf-reader: Fix reader::initialize to clear per corpus data

After cleaning up re-initialization sequence of the the CTF reader ,
Claudiu Ianculescu suggested that I look into the DWARF reader's
initialization sequence as well.  Lo and behold, the
dwarf::reader::read_debug_info_into_corpus calls
reader::clear_per_corpus_data while reader::initialize does not.

This patch moves the call to reader::clear_per_corpus_data into
reader::initialize.  It makes the code consistent with what we are now
doing in the CTF reader.

* src/abg-dwarf-reader.cc (reader::initialize):  Call
clear_per_corpus_data.
(reader::read_debug_info_into_corpus): Remove the call to
clear_per_corpus_data from here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
5 months agoir: Cache the pretty representation used during pre-canonicalization type sorting
Dodji Seketeli [Fri, 21 Jun 2024 10:17:25 +0000 (12:17 +0200)]
ir: Cache the pretty representation used during pre-canonicalization type sorting

Profiling showed that during pre-canonicalization types sorting (which
uses type_topo_comp and decl_topo_comp sorting functors) we spend a
lot of time computing the pretty representation of types and decls
invoked from type_topo_comp::operator() and
decl_topo_comp::operator().

This patch thus uses type_base::get_cached_pretty_representation and
introduces a new similar decl_base::get_cached_pretty_representation
to cache the pretty representation of types and decls and re-use that
representation instead of computing it over and over.

Together with the previous patch of this series, the time spent to
analyze a Linux Kernel tree went from ~ 55 minutes to around 1m15s
using a non-optimized build of libabigail.

* include/abg-ir.h (decl_base::get_cached_pretty_representation):
Declare new member function.
* src/abg-ir-priv.h ({type,decl}_topo_comp::operator()): Use
{type,decl}_base::get_cached_pretty_representation instead of
get_pretty_representation.:
* src/abg-ir.cc (decl_base::priv::{internal_cached_repr_,
cached_repr}): Define new data members.
(decl_base::get_cached_pretty_representation):
Define new member function.
(type_base::get_cached_pretty_representation): Cache pretty
representation even for non-canonicalized types.  Fix comments.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
5 months agoctf-reader: Fix re-initialization of the CTF reader
Dodji Seketeli [Fri, 21 Jun 2024 10:00:26 +0000 (12:00 +0200)]
ctf-reader: Fix re-initialization of the CTF reader

When analyzing a Linux Kernel tree made of vmlinux and loadable module
binaries, the same (CTF) binary reader is re-used to load every single
binaries in a loop.  That can be seen, for instance, by reading the
code of load_vmlinux_corpus in abg-tools-utils.cc.

As part of that process, abigail::ctf::reader::initialize is invoked
prior to using the reader to read type information from each binary.

But then, looking at things a bit closer, I realized that
ctf::reader::initialize is failing to reset the reader::ctfa data
member.  That leads to a memory leak that was making things grow
out of proportion.

Also, the resetting code fails to actually clear out the map of types
that are to be sorted and canonicalized.  That leads to unnecessarily
sorting huge amounts of types.

The patch address the two points above.

Apart from the obvious gain in code integrity, this patch
significantly reduces the time taken to analyze a Linux Kernel tree.
Please note that the subsequent patch coming after this one will
reduce that time even further.

* src/abg-ctf-reader.cc (reader::reader): Initialize ctfa,
ctf_sect, symtab_sect and strtab_sect data members.
(reader::initialize): In the overload taking no argument, make
sure to free the ctfa data member before setting it to nullptr.
In the overload that takes arguments, make sure to invoke
reader::initialize() to really free the data used.  Also, improve
the comments.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
5 months agoctf-reader: Add time logging to CTF reader
Claudiu Zissulescu [Wed, 19 Jun 2024 15:31:59 +0000 (18:31 +0300)]
ctf-reader: Add time logging to CTF reader

Log the time spent while reading the CTF archive and canonicalizing it.

    * src/abg-ctf-reader.cc (do_log()): Getter of the do_log flag.
    (read_corpus()): Add time logging.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
5 months agoctf-reader: Optimize calling sorting function for functions and variables.
Claudiu Zissulescu [Wed, 19 Jun 2024 15:30:48 +0000 (18:30 +0300)]
ctf-reader: Optimize calling sorting function for functions and variables.

Sorting the functions and variables is done twice. First in the
process_ctf_archive() and second in read_corpus().  However, we need
to call them only once when we do the canonicalization of all types
and functions.  Thus, move canonicalization of types in read_corpus()
and perfom only once sorting the functions and types.

* abg-ctf-reader.cc (process_ctf_archive()): Move
canonicalize_all_types(), sort_functions() and sort_variables()...
(read_corpus()): ...here, just after calling process_ctf_archive().

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
5 months agoleaf-reporter: Fix build with gcc 4.9.
Romain Geissler [Wed, 12 Jun 2024 20:59:12 +0000 (20:59 +0000)]
leaf-reporter: Fix build with gcc 4.9.

* src/abg-leaf-reporter.cc (leaf_reporter::report): In the
overload for corpus_diff, avoid using auto type deduction in
for-each loop.

Signed-off-by: Romain Geissler <romain.geissler@amadeus.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
6 months agobtf-reader: Fix re-use of the BTF reader for several binaries in a row
Dodji Seketeli [Fri, 31 May 2024 13:29:48 +0000 (15:29 +0200)]
btf-reader: Fix re-use of the BTF reader for several binaries in a row

When analyzing a Linux Kernel tree, the BTF reader needs to be reset
after each binary (vmlinux or module) read.  It turns out the reset
was not being done properly.  Fixed thus.  Also, I noticed that
reader::read_debug_info_into_corpus would not return an empty corpus
when no BTF information was found in the binary.  Fixed as well.

* src/abg-btf-reader.cc (reader::initialize): Free the btf handle
first thing as part of the re-initialization.
(reader::~reader): Once the BTF handle has been freed, set it to
nil to show that it's been deleted.
(reader::read_debug_info_into_corpus): If no BTF handle could be
retrieved then it means no BTF data was found on the binary.
Thus, return an empty corpus.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
6 months agoabidw: make the --lt option support --btf
Dodji Seketeli [Fri, 31 May 2024 12:03:23 +0000 (14:03 +0200)]
abidw: make the --lt option support --btf

When building the ABI for a Linux kernel that has BTF and DWARF debug
info, the --btf option doesn't select the BTF debug info if DWARF is
also present.

Fixed thus.

* tools/abidw.cc (load_kernel_corpus_group_and_write_abixml):
Support --btf.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
6 months agotools-utils.cc: Support collecting kernel binary paths build from sources
Dodji Seketeli [Fri, 31 May 2024 11:56:52 +0000 (13:56 +0200)]
tools-utils.cc: Support collecting kernel binary paths build from sources

When 'abidw --lt /some/dir' runs with /some/dir being a linux kernel
tree built from source (as opposed to coming from a distribution),
get_binary_paths_from_kernel_dist misbehaves because it expects to
find modules somewhere under/lib/modules.  This patch makes it support
linux kernel trees built from source by looking for modules all over
the place, wherever they might be.

* src/abg-tools-utils.cc (get_binary_paths_from_kernel_dist): Look
for kernel modules under the root directory by default.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
6 months agoBug 31793 - tools-utils: Avoid endless loop in is_regular_file for directories
Dodji Seketeli [Fri, 31 May 2024 11:54:25 +0000 (13:54 +0200)]
Bug 31793 - tools-utils: Avoid endless loop in is_regular_file for directories

When is_regular_file is given a directory, it loops endlessly.  Oops.

Fixed thus.

* src/abg-tools-utils.cc (is_regular_file): Loop on symbolic links
only.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months ago{btf,dwarf,ctf,abixml}-reader: Fix size of subrange type users/dodji/fix-subrange-size users/dodji/try-fix-subrange-size
Dodji Seketeli [Wed, 15 May 2024 10:40:18 +0000 (12:40 +0200)]
{btf,dwarf,ctf,abixml}-reader: Fix size of subrange type

While looking at something else, it appeared that the process of
setting the size of the array_type_def::subrange_type is wrong for all
front-ends.

For this patch, I went back to read the DWARF 5 specification at
"5.13/ Subrange Type Entries".

Basically, the size of the subrange type as described by the
DW_TAG_subrange_type DIE is set either:

    * by the size of the base type designated by the DW_AT_type
      attribute.

    * or by the DW_AT_byte_size or DW_AT_bit_size attribute that might
      be present on the DIE.

That is different from the length property carried by the subrange
type.

The patch updates the four front-rends (DWARF, BTF, CTF and ABIXML) to
fix the setting process of the size of the subrange type and adjusts
the testsuite accordingly.

* src/abg-btf-reader.cc (reader::build_array_type): The size of
the subrange is not defined specifically.  Let's set it to the
default address size of the translation unit.
* src/abg-ctf-reader.cc (build_array_ctf_range): If no basis type
was found, then set the size of the subrange type to the default
address size of the translation unit.
* src/abg-dwarf-reader.cc (build_subrange_type): Consider the
DW_AT_byte_size and DW_AT_bit_size attribute of
DW_TAG_subrange_type if present.  Otherwise, if the basis type is
present, its size as the size of the subrange type.  Otherwise,
use the default address size of the translation unit as the size
of the subrange type.
* src/abg-ir.cc (array_type_def::subrange_type::subrange_type): If
the underlying (basis) type is present, then use its size as the
size of the subrange type.  Otherwise the size is zero.
(array_type_def::subrange_type::set_underlying_type): Update the
size of the subrange when setting a new underlying (basis) type.
* src/abg-reader.cc (build_subrange_type): Read and set the size
of the subrange.
* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-1.txt:
Adjust.
* tests/data/test-abidiff-exit/ada-subrange/test1-ada-subrange/test1-ada-subrange-report-2.txt:
Likewise.
* tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-1.txt:
Likewise.
* tests/data/test-abidiff-exit/ada-subrange/test2-ada-subrange-redundant/test2-ada-subrange-redundant-report-2.txt:
Likewise.
* tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64--2.24.2-30.fc30.x86_64-report-0.txt:
Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoconfigure: Fix detection of BTF header to enable the BTF front-end
Dodji Seketeli [Wed, 15 May 2024 11:33:20 +0000 (13:33 +0200)]
configure: Fix detection of BTF header to enable the BTF front-end

Cestmir Kalina reported that running configure with --enable-btf with
no BTF header present on the system wrongly leads to the BTF
front-end of libabigail being enabled, and later leads to
compilation/installation errors.

This patch fixes that by ensuring that the ENABLE_BTF variable set by
the --enable-btf option handling code is not reused later during
actual btf.h header file detection code.

* configure.ac: Use a new HAS_BTF_HEADERS to store the detection
status for the btf.h header.  Emit a better notice message when
the BTF header file is found.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Tested-by: Cestmir Kalina <ckalina@redhat.com>
7 months agobtf-reader: Ignore BTF nodes that ought to be ignored
Dodji Seketeli [Fri, 10 May 2024 11:52:22 +0000 (13:52 +0200)]
btf-reader: Ignore BTF nodes that ought to be ignored

For now, the BTF nodes BTF_KIND_DECL_TAG, BTF_KIND_DATASEC, and
BTF_KIND_UNKN are ignored by libabigail, in practice.  We should thus
not abort when we encounter them.  Fixed thus.  Many thanks to Cestmir
Kalina for reporting this.

* src/abg-btf-reader.cc (build_ir_node_from_btf_type): Ignore and
return nil for node of kind BTF_KIND_DECL_TAG, BTF_KIND_DATASEC,
and BTF_KIND_UNKN.  For all other nodes, abort.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
# Veuillez saisir le message de validation pour vos
modifications. Les lignes # commençant par '#' seront ignorées, et
un message vide abandonne la validation.  # # Sur la branche
master # Votre branche est Ã  jour avec 'origin/master'.  # #
Modifications qui seront validées : # modifié :
src/abg-btf-reader.cc # # Fichiers non suivis: #
doc/api/libabigail.doxy.bak # patches/ # prtests/ # #
------------------------ >8 ------------------------ # Ne touchez
pas Ã  la ligne ci-dessus.  # Tout ce qui suit sera Ã©liminé.
diff --git a/src/abg-btf-reader.cc b/src/abg-btf-reader.cc
index f22e92bf..67206bb4 100644
--- a/src/abg-btf-reader.cc
+++ b/src/abg-btf-reader.cc
@@ -486,12 +486,16 @@ public:

 #ifdef WITH_BTF_KIND_TYPE_TAG
    case BTF_KIND_TYPE_TAG/* Type Tag */:
+     break;
 #endif
 #ifdef WITH_BTF_KIND_DECL_TAG
    case BTF_KIND_DECL_TAG/* Decl Tag */:
+     break;
 #endif
    case BTF_KIND_DATASEC/* Section */:
+     break;
    case BTF_KIND_UNKN/* Unknown */:
+     break;
    default:
      ABG_ASSERT_NOT_REACHED;
      break;

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agodwarf-reader,ir: Unify type sorting & sort types before c14n
Dodji Seketeli [Tue, 7 May 2024 01:06:24 +0000 (03:06 +0200)]
dwarf-reader,ir: Unify type sorting & sort types before c14n

This fixes the temporary breakage I have introduced by committing too
soon the patch below that should have been committed after the type
hashing patch:

    d26bd3d2 dwarf-reader,ir: Merge member fns of classes

Oops.

That patch introduces some instability in the ABIXML output due to the
fact that sorting of function types in particular is not deterministic
enough.  I believe that because the sorting is using the internal
pretty representation of function types, it can introduce instability
in the sorting of two types that are equivalent modulo one typedef,
because the internal pretty representation strips typedefs off of
function return and parameter types.  This patch fixes that by using
the type_topo_comp operator used in the IR for sorting types, instead
of having a different sorting routine in the ABIXML writer.  Another
instability is due to the fact that method types where there is no
parameter beside the implicit "this" parameter and that are different
due to const-ness of the enclosing class could not be told apart.  The
patch fixes that as well.

The patch also sorts types before canonicalizing them in the ABIXML
reader, so that type canonicalization happens in the same order (in
DWARF and ABIXML) to minimize changes in canonicalization results
between DWARF and ABIXML.  This should hopefully help minimize
self-comparison errors.

Note that sorting types (based on their pretty representation) before
canonicalizing them might incur some (temporary) slowness that I
believe should be handled by the coming type hashing patch set.  If we
see that the slowness is not bearable, we might remove that sorting at
some point.  For now, let's keep it for testing purposes.

* src/abg-ctf-reader.cc (reader::canonicalize_all_types): Use a
temporary vector as input for ir::canonicalize_types because it
needs an ordered container as it now sorts types before
canonicalizing them.
* src/abg-dwarf-reader.cc (reader::types_to_canonicalize): Add a
non-const overload for this accessor.
* src/abg-ir-priv.h (compare_using_locations)
(is_ptr_ref_or_qual_type): Add a declaration for these functions
defined in abg-ir.cc.
(struct decl_topo_comp, struct type_topo_comp): Move these here,
from abg-ir.cc.
(canonicalize_types): Sort the types before canonicalizing them.
* src/abg-ir.cc (compare_using_locations): Turn this from static
to non-static, now that it's declared in abg-ir-priv.h.
(struct decl_topo_comp, struct type_topo_comp): Move these into
abg-ir-priv.h.
* src/abg-reader.cc: Include abg-ir-priv.h.
(reader::perform_late_type_canonicalizing): Use
ir::canonicalize_types, rather than canonicalizing types one by
one.
* src/abg-writer.cc: Include abg-ir-priv.h.
(struct type_topo_comp): Remove.
(write_context::sort_types): Use type_topo_comp from abg-ir-priv.h
instead of type_topo_comp that was removed.
* tests/data/test-annotate/test13-pr18894.so.abi: Adjust.
* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
Likewise.
* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
Likewise.
* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
Likewise.
* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
* tests/data/test-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/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.
* 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>
7 months agoelf-reader: Avoid crashing when looking at non-existing variable symbol
Dodji Seketeli [Thu, 9 May 2024 16:02:27 +0000 (18:02 +0200)]
elf-reader: Avoid crashing when looking at non-existing variable symbol

* src/abg-elf-reader.cc (reader::variable_symbol_is_exported): Do
not crash when the symbol we are looking at is non-present.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoSuppress patch file that was wrongly added to the repository
Dodji Seketeli [Mon, 6 May 2024 17:02:19 +0000 (19:02 +0200)]
Suppress patch file that was wrongly added to the repository

I have wrongly added a patch to the source repository.  Oops.  Remove it.

* patches/0001-WIP-Emit-read-undefined-interfaces-to-from-ABIXML.patch:
Remove from the repository.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agotest-read-common: Fix error message
Dodji Seketeli [Tue, 26 Mar 2024 15:20:18 +0000 (16:20 +0100)]
test-read-common: Fix error message

The error message in test_task::run_abidw in test-read-common.cc is
wrong.  Fixed thus.  Also, emit the error message directly to the standard
error as the error is detected.

* tests/test-read-common.cc (test_task::run_abidw): Fix error
message and emit it to stderr directly.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agodwarf-reader,ir: Merge member fns of classes
Dodji Seketeli [Tue, 26 Mar 2024 23:43:15 +0000 (00:43 +0100)]
dwarf-reader,ir: Merge member fns of classes

When looking at something else, I realized that in DWARF, two classes
C and C' of the same name and coming from the same corpus might not
have the same member functions that are defined.  This is probably
because for a given translation unit, some compilers emit debug info
only for the member functions that are used somehow.

So, depending on which of C or C' is the canonical class in the end,
we will not necessarily have the same member functions emitted in
ABIXML.  That is annoying.  So there was a kludge in
maybe_adjust_canonical_type to ensure that the canonical type has all
the member functions of the types belonging to same class of
equivalence.

This patch adds a pass before type canonicalization in the DWARF
reader to ensure that all classes of the same name in a given corpus
have the same member functions.  The patch thus removes the now
unnecessary kludge from maybe_adjust_canonical_type and asserts the
impossibility of the member function discrepancy.

* src/abg-dwarf-reader.cc (reader::{copy_missing_member_functions,
contains_anonymous_class, merge_member_functions_of_classes,
merge_member_functions_in_classes_of_same_names}): Define new
member functions.
(reader::read_debug_info_into_corpus): Call the reader::new
merge_member_functions_in_classes_of_same_names.
* src/abg-ir.cc (maybe_adjust_canonical_type): When looking at the
canonical type C of a type T, if they both come from the same
corpus, assert that C has all the member functions of T.  This
because the DWARF reader now ensures that all types have the same
name in a given corpus have the same member functions.
* tests/data/test-annotate/test14-pr18893.so.abi: Adjust.
* 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-read-dwarf/test-libandroid.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/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.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agodwarf-reader,ir: Improve detection of method types & implicit parms
Dodji Seketeli [Fri, 3 May 2024 21:05:26 +0000 (23:05 +0200)]
dwarf-reader,ir: Improve detection of method types & implicit parms

There is a confusion in the DWARF reader about static member functions
and non-static member functions.  With recent versions of DWARF, a
member function with the DW_AT_object_pointer attribute is known to
have a this-pointer and thus designates a non-static member function.
DWARF emitted by gcc 4.4.x and previous compiler didn't emit the
DW_AT_object_pointer so we need to look at the first parameter of the
member function, make sure it's artificial and pointers to a pointer
to the same class as the class of the current member function.

This patch avoids to confuse static and non-static member functions by
telling apart types of static member functions, non-static member
function and non member functions. This fixes the representation of
several method types and function declaration signatures across the
test suite.

* include/abg-ir.h (method_type::get_is_for_static_method): Add
new method.
* src/abg-dwarf-reader.cc (fn_die_first_parameter_die)
(member_fn_die_has_this_pointer, die_peel_typedef): Define new
static functions.
(die_this_pointer_is_const): Make this support DIEs representing
const pointers.
(die_function_type_is_method_type): Use the new
member_fn_die_has_this_pointer function rather than (wrongly) open
coding its functionality.  If the (member) function DIE has no
this pointer DIE and if the function is at class scope, then we
are looking a static member function.
(finish_member_function_reading): Use the new
method::get_is_for_static_method method rather than open-coding
its functionality.
* src/abg-ir.cc (method_type::get_is_for_static_method): Define
new method.
(type_topo_comp::operator()): In this comparison
operator for types, if two method types have the same string
representation then if one method type is for a static method,
then make the non-static method type come first.
(function_type::get_first_non_implicit_parm): The first parameter
of a function can only carry the "this pointer" if it's
artificial.
* tests/data/test-abidiff-exit/PR31513/reported/PR31513-reported-report-1.txt:
Adjust.
* tests/data/test-abidiff/test-struct1-report.txt: Likewise.
* tests/data/test-abidiff/test-struct1-v0.cc.bi: Likewise.
* tests/data/test-abidiff/test-struct1-v1.cc.bi: Likewise.
* tests/data/test-annotate/test14-pr18893.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-dwarf/test42-PR21296-clanggcc-report0.txt:
Likewise.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
Likewise.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt:
Likewise.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt:
Likewise.
* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
Likewise.
* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-1.txt:
Likewise.
* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
Likewise.
* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
* tests/data/test-read-dwarf/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/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
Likewise.
* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
Likewise.
* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
Likewise.
* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agowriter: Fix control of emitting parm names in function types
Dodji Seketeli [Tue, 26 Mar 2024 22:44:54 +0000 (23:44 +0100)]
writer: Fix control of emitting parm names in function types

Emitting parameter names in function types should be controlled by the
set_write_parameter_names function.  It turns out it is not.  Fixed
thus and adjust testannotate and testreadwarf to avoid emitting
parameter names altogether.  This removes some rare randomness in the
tests output.

* src/abg-writer.cc (write_function_type): Control emitting of
parameter names with the write_context::get_write_parameter_names
property.
* tests/test-annotate.cc (main): Do not emit function parameter
names.
* tests/test-read-dwarf.cc (main): Likewise.
* tests/data/test-annotate/libtest23.so.abi: Adjust.
* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
* tests/data/test-annotate/test0.abi: Likewise.
* tests/data/test-annotate/test1.abi: Likewise.
* tests/data/test-annotate/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/test4.so.abi: Likewise.
* tests/data/test-annotate/test6.so.abi: Likewise.
* tests/data/test-annotate/test8-qualified-this-pointer.so.abi:
Likewise.
* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
Likewise.
* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
* tests/data/test-read-dwarf/PR24378-fn-is-not-scope.abi:
Likewise.
* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.
* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
Likewise.
* tests/data/test-read-dwarf/PR26261/PR26261-exe.abi: Likewise.
* tests/data/test-read-dwarf/PR27700/test-PR27700.abi: Likewise.
* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
Likewise.
* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
* tests/data/test-read-dwarf/test-PR26568-1.o.abi: Likewise.
* tests/data/test-read-dwarf/test-PR26568-2.o.abi: Likewise.
* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
* tests/data/test-read-dwarf/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/test4.so.abi: Likewise.
* tests/data/test-read-dwarf/test4.so.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/test8-qualified-this-pointer.so.abi:
Likewise.
* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi:
Likewise.
* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoir: Make IR node visitor aware of non-canonicalized types
Dodji Seketeli [Fri, 3 May 2024 13:12:37 +0000 (15:12 +0200)]
ir: Make IR node visitor aware of non-canonicalized types

is_non_canonicalized_type is the function that decides which type
should be canonicalized or not.  So, code that expects a type to be
canonicalized should comply with the rule of
is_non_canonicalized_type, aka The Rule.  It turns out, the IR node
visitor code fails to comply with The Rule.  Fixed thus.  Note that
with this commit, the program build/tests/testirwalker now works fine
on itself.  Many thanks to Cestmir Kalina who noticed and reported the
issue.

* src/abg-ir.cc (ir_node_visitor::{mark_type_node_as_visited,
type_node_has_been_visited}): Invoke is_non_canonicalized_type to
know if we should expect a type to have a canonical type or not.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoir,writer: Fix function type naming & fn type annotation in ABIXML users/dodji/try-hack
Dodji Seketeli [Fri, 26 Apr 2024 18:59:32 +0000 (20:59 +0200)]
ir,writer: Fix function type naming & fn type annotation in ABIXML

While looking at something else, it occurred to me that function type
annotation in ABIXML (as emitted by abidw --annotate) is wrong,
especially when it comes to pointer to member function types.  Now
that we support pointer to member function types naming, just using
ir::get_type_name in the annotate function should be enough to do the
trick.  And this is what this patch does.

Also, I realized that get_function_type_name was wrongly invoking
get_pretty_representation on the return type of the function type,
instead of just emitting its type name.  This patch fixes that as
well.

* src/abg-ir.cc (get_function_type_name, get_method_type_name):
Use get_type_name in lieu of get_pretty_representation.
* src/abg-writer.cc (annotate): In the overload for function_type,
use get_function_name instead of open coding function type
representations.
* tests/data/test-annotate/test-pointer-to-member-1.o.annotated.abi: Adjust.
* 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/PR25058-liblttng-ctl-report-1.txt: Likewise.
* tests/data/test-diff-pkg-ctf/gmp-6.x.x86_64-report-0.txt: Likewise.
* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
Likewise.
* tests/data/test-read-dwarf/PR25007-sdhci.ko.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.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agotests/runtestabidb?.sh.in: Use bash shebang
Sam James [Fri, 19 Apr 2024 02:23:11 +0000 (03:23 +0100)]
tests/runtestabidb?.sh.in: Use bash shebang

'function x() { ... }' is a bashism, but /bin/sh may be another shell,
like dash. Just use an explicit /bin/bash shebang as the file relies on
a few other bashisms like 'type'.

    * tests/runtestabidb[1-2].sh.in: Use bash shebang.

Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agofedabipkgdiff: Cleanup output of ABI comparison
Dodji Seketeli [Mon, 29 Apr 2024 13:06:47 +0000 (15:06 +0200)]
fedabipkgdiff: Cleanup output of ABI comparison

The output of fedabipkgidiff doesn't clearly say when two
(sub)packages have no ABI change.

This patch fixes that.  The patch also trims unnecessary white spaces
from the output of fedabipkgdiff.  As a result, the patch adjusts the
expected reference output files.

* tools/fedabipkgdiff: Adjust copyright year
(abipkgdiff): Strip out trailing spaces from the stdout
string.  Emit a clear message when no ABI change was found.
* 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:
Adjust.
* tests/data/test-fedabipkgdiff/test2-dbus-glib-0.100.2-2.fc20--dbus-glib-0.106-1.fc23-report-0.txt:
Adjust.
* tests/data/test-fedabipkgdiff/test3-dbus-glib-0.100.2-2.fc20.i686--dbus-glib-0.106-1.fc23.i686-report-0.txt:
Adjust.
* 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:
Adjust.
* tests/data/test-fedabipkgdiff/test5-same-dir-dbus-glib-0.100.2-2.fc20.x86_64--dbus-glib-0.106-1.fc23.x86_64-report-0.txt:
Adjust.
* tests/data/test-fedabipkgdiff/test6-nss-util-3.12.6-1.fc14.x86_64--nss-util-3.24.0-2.0.fc25.x86_64-report-0.txt:
Adjust.
* tests/data/test-fedabipkgdiff/test7-self-compare-from-fc23-dbus-glib-report-0.txt:
Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoconfigure,abidb: Make the libarchive python module optional for abidb
Frank Ch. Eigler [Fri, 26 Apr 2024 08:30:42 +0000 (10:30 +0200)]
configure,abidb: Make the libarchive python module optional for abidb

Some distributions don't have the libarchive python module packaged.

This patch makes that module optional and enables abidb to function
without it, as it's only necessary for the support of the '--archive'
command line option of the abidb program.

* configure.ac: Detect the libarchive python module as an optional
dependency for the abidb program.  So far, only the git python
module remains a hard dependency.
* tools/abidb (main): Do not support the '--archive' command line
option if the libarchive python module is not present.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoUpdate Copyright for year 2024
Dodji Seketeli [Fri, 26 Apr 2024 13:29:50 +0000 (15:29 +0200)]
Update Copyright for year 2024

* update-copyright.sh: Update the date in this script.  Running
the script then yields the changes below.
* include/abg-btf-reader.h: Update copyright year as a result of
running update-copyright.sh above.
* include/abg-comp-filter.h: Likewise.
* include/abg-comparison.h: Likewise.
* include/abg-config.h: Likewise.
* include/abg-corpus.h: Likewise.
* include/abg-ctf-reader.h: Likewise.
* include/abg-cxx-compat.h: Likewise.
* include/abg-diff-utils.h: Likewise.
* include/abg-dwarf-reader.h: Likewise.
* include/abg-elf-based-reader.h: Likewise.
* include/abg-elf-reader.h: Likewise.
* include/abg-fe-iface.h: Likewise.
* include/abg-fwd.h: Likewise.
* include/abg-hash.h: Likewise.
* include/abg-ini.h: Likewise.
* include/abg-interned-str.h: Likewise.
* include/abg-ir.h: Likewise.
* include/abg-libxml-utils.h: Likewise.
* include/abg-reader.h: Likewise.
* include/abg-regex.h: Likewise.
* include/abg-reporter.h: Likewise.
* include/abg-sptr-utils.h: Likewise.
* include/abg-suppression.h: Likewise.
* include/abg-tools-utils.h: Likewise.
* include/abg-traverse.h: Likewise.
* include/abg-viz-common.h: Likewise.
* include/abg-viz-dot.h: Likewise.
* include/abg-viz-svg.h: Likewise.
* include/abg-workers.h: Likewise.
* include/abg-writer.h: Likewise.
* src/abg-btf-reader.cc: Likewise.
* src/abg-comp-filter.cc: Likewise.
* src/abg-comparison-priv.h: Likewise.
* src/abg-comparison.cc: Likewise.
* src/abg-config.cc: Likewise.
* src/abg-corpus-priv.h: Likewise.
* src/abg-corpus.cc: Likewise.
* src/abg-ctf-reader.cc: Likewise.
* src/abg-default-reporter.cc: Likewise.
* src/abg-diff-utils.cc: Likewise.
* src/abg-dwarf-reader.cc: Likewise.
* src/abg-elf-based-reader.cc: Likewise.
* src/abg-elf-helpers.cc: Likewise.
* src/abg-elf-helpers.h: Likewise.
* src/abg-elf-reader.cc: Likewise.
* src/abg-fe-iface.cc: Likewise.
* src/abg-hash.cc: Likewise.
* src/abg-ini.cc: Likewise.
* src/abg-internal.h: Likewise.
* src/abg-ir-priv.h: Likewise.
* src/abg-ir.cc: Likewise.
* src/abg-leaf-reporter.cc: Likewise.
* src/abg-libxml-utils.cc: Likewise.
* src/abg-reader.cc: Likewise.
* src/abg-regex.cc: Likewise.
* src/abg-reporter-priv.cc: Likewise.
* src/abg-reporter-priv.h: Likewise.
* src/abg-suppression-priv.h: Likewise.
* src/abg-suppression.cc: Likewise.
* src/abg-symtab-reader.cc: Likewise.
* src/abg-symtab-reader.h: Likewise.
* src/abg-tools-utils.cc: Likewise.
* src/abg-traverse.cc: Likewise.
* src/abg-viz-common.cc: Likewise.
* src/abg-viz-dot.cc: Likewise.
* src/abg-viz-svg.cc: Likewise.
* src/abg-workers.cc: Likewise.
* src/abg-writer.cc: Likewise.
* tests/print-diff-tree.cc: Likewise.
* tests/test-abicompat.cc: Likewise.
* tests/test-abidiff-exit.cc: Likewise.
* tests/test-abidiff.cc: Likewise.
* tests/test-alt-dwarf-file.cc: Likewise.
* tests/test-core-diff.cc: Likewise.
* tests/test-cxx-compat.cc: Likewise.
* tests/test-diff-dwarf-abixml.cc: Likewise.
* tests/test-diff-dwarf.cc: Likewise.
* tests/test-diff-filter.cc: Likewise.
* tests/test-diff-pkg.cc: Likewise.
* tests/test-diff-suppr.cc: Likewise.
* tests/test-diff2.cc: Likewise.
* tests/test-dot.cc: Likewise.
* tests/test-elf-helpers.cc: Likewise.
* tests/test-ini.cc: Likewise.
* tests/test-ir-walker.cc: Likewise.
* tests/test-kmi-whitelist.cc: Likewise.
* tests/test-lookup-syms.cc: Likewise.
* tests/test-read-btf.cc: Likewise.
* tests/test-read-ctf.cc: Likewise.
* tests/test-read-dwarf.cc: Likewise.
* tests/test-read-write.cc: Likewise.
* tests/test-svg.cc: Likewise.
* tests/test-symtab-reader.cc: Likewise.
* tests/test-symtab.cc: Likewise.
* tests/test-tools-utils.cc: Likewise.
* tests/test-types-stability.cc: Likewise.
* tests/test-utils.cc: Likewise.
* tests/test-utils.h: Likewise.
* tools/abicompat.cc: Likewise.
* tools/abidiff.cc: Likewise.
* tools/abidw.cc: Likewise.
* tools/abilint.cc: Likewise.
* tools/abipkgdiff.cc: Likewise.
* tools/abisym.cc: Likewise.
* tools/binilint.cc: Likewise.
* tools/fedabipkgdiff: Likewise.
* tools/kmidiff.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoconfigure.ac: Update version to 2.6
Dodji Seketeli [Mon, 22 Apr 2024 13:50:12 +0000 (15:50 +0200)]
configure.ac: Update version to 2.6

configure.ac: Update to 2.6 version.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months ago{ctf,btf}-reader: Document the namespace for nicer apidoc
Dodji Seketeli [Thu, 18 Apr 2024 15:53:52 +0000 (17:53 +0200)]
{ctf,btf}-reader: Document the namespace for nicer apidoc

The apidoc is not generating any documentation for the libabigail::btf
and libabigail::ctf namespaces.

It turns out I need to add some doxygen comment to the these namespaces
in the source code.  Fixed thus.

* include/abg-btf-reader.h (namespace btf): Add doxygen comment.
Just adding it to the *.cc won't cut it, I am not sure why.
* include/abg-ctf-reader.h (namespace ctf): Likewise.
* src/abg-btf-reader.cc (namespace btf): Add doxygen comment.
* src/abg-ctf-reader.cc (namespace ctf): Add doxygen commit.
(create_reader, reset_reader): Fix doxygen comments.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agodoc/api/libabigail.doxy: Update to newer version.
Dodji Seketeli [Thu, 18 Apr 2024 15:52:22 +0000 (17:52 +0200)]
doc/api/libabigail.doxy: Update to newer version.

When doing "make doc", doxygen issues a lot of warning due to the the
configuration file using old property values.

This patch updates the doxygen configuration file for the apidoc using
doxygen -u.

* doc/api/libabigail.doxy: Update using doxygen -u.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agodoc/website/mainpage.txt: Update for 2.5 release
Dodji Seketeli [Thu, 18 Apr 2024 14:33:41 +0000 (16:33 +0200)]
doc/website/mainpage.txt: Update for 2.5 release

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoChangeLog: Update for 2.5 release libabigail-2.5
Dodji Seketeli [Wed, 17 Apr 2024 10:40:01 +0000 (12:40 +0200)]
ChangeLog: Update for 2.5 release

* ChangeLog: Update for 2.5 release by running the "make
update-changelog" command.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoNEWS: Update for 2.5 release
Dodji Seketeli [Wed, 17 Apr 2024 10:34:40 +0000 (12:34 +0200)]
NEWS: Update for 2.5 release

* NEWS: Update for the 2.5 release with the command git
shortlog libabigail-2.4..HEAD.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoconfigure: Add option to disable abidb
Dodji Seketeli [Thu, 18 Apr 2024 10:13:00 +0000 (12:13 +0200)]
configure: Add option to disable abidb

While looking at packaging libabigail for EPEL8, it turned out abidb
requires python 3.9 for the type hints on function definitions.  Yet,
EPEL8 has an older python.

This patch adds a --disable-abidb option to configure to handle EPEL8.

* configure.ac: Add a --disable-abidb option to configure to
disable the abidb tool and related tests.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agotests/runtestabidb?.sh.in: Fix git initialization
Dodji Seketeli [Wed, 17 Apr 2024 13:47:05 +0000 (15:47 +0200)]
tests/runtestabidb?.sh.in: Fix git initialization

* tests/runtestabidb[1-2].sh.in: Initialize email & user name
          for the local git repository.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 months agoBug 31646: Fix type suppression tactics for webkit2gtk3
Dodji Seketeli [Mon, 15 Apr 2024 08:16:21 +0000 (10:16 +0200)]
Bug 31646: Fix type suppression tactics for webkit2gtk3

By default, using abidw --abidiff on the binary
/usr/lib64/libwebkit2gtk-4.0.so.37 on the ppc64le platform takes more
than 50GB of RAM and ooms on my system.  That is why a number of
suppression specifications have been put in place in the
default.abignore file that is installed by default on the system.
With that suppression specification however, abidw --abidiff hits an
assert and crashes.

That is because the suppression specification rule below is too eager
and thus removes parameters from some function's signature, in the
final internal representation:

    [suppress_type]
      soname_regexp = libwebkit2?gtk-.*\\.so.*
      name_regexp = (^std::.*|WebCore::.*|WebKit::.*)
      drop = true

An example of function signature that got changed (in the IR) because
of this suppression specification is:

This function signature:

    WebKitAuthenticationScheme
    webkit_authentication_request_get_scheme(WebKitAuthenticationRequest*)

becomes (after applying the suppression specification above):

    void
    webkit_authentication_request_get_scheme()

Woops.  That is not good.

To address that problem, this patch changes that suppression
specification to make libabigail transform those types into opaque
types.  An opaque struct, class or enum is essentially a
declaration-only type of the same kind and name.

So the suppression specification above becomes:

    [suppress_type]
      # Drop all standard c++ types on the floor like before.
      soname_regexp = libwebkit2?gtk-.*\\.so.*
      name_regexp = ^std::.*
      drop = true

    [suppress_type]
      # Transform all C++ types in the WebCore and WebKit namespaces into
      # opaque types.  These are essentially internal types of libwebkit2
      # anyway.  This greatly reduces the size of the in-memory working set.
      label = libabigail::OPAQUE_TYPE_LABEL
      soname_regexp = libwebkit2?gtk-.*\\.so.*
      name_regexp = (WebCore::.*|WebKit::.*)
      drop = true

Notice the introduction of the new special label
"libabigail::OPAQUE_TYPE_LABEL".  This new special label is what makes
the suppression engine of libabigail transform a type (that matches
that suppression specification) into an opaque type, rather than
dropping it on the floor.

The patch then adapts the code of the suppression engine to detect
this special label for the purpose of transforming types into opaque
types.  The patch normalizes the use of the term "opaque type" instead
of "private type" that was used previously in the code.

The patch fixes a bug in the code of get_opaque_version_of_type that
prevents this function from working on types with no location
information.

While working on this, I have noticed that the abipkgdiff has a bug
that was making it ignore suppression specifications provided via the
--suppression option.  The patch fixes that.

I have noticed that abipkgdiff --self-check completely ignores all
suppression specifications provided either via --suppression or
indirectly via devel packages.  The patch fixes that.

Last but not least, fedabipkgdiff --self-compare completely ignores
suppression specifications too!  The patch fixes that as well.

With all those fixes, the system now takes around 7GB of RAM and ~ 30
minutes to complete the analysis of the webkit2gtk3 package, using a
non-optimized libabigail build.

The command I use is:

    $ time tools/fedabipkgdiff --debug --self-compare --abipkgdiff build/tools/abipkgdiff --suppressions default.abignore -a --from fc39 webkit2gtk3

    [...]

    [DEBUG] Result from run_abipkgdiff: 0, in: 0:29:00.088735
    [DEBUG] Result from self_compare_rpms_from_distro: 0, in: 0:29:20.721748

    real 29m20,846s
    user 29m4,561s
    sys         2m41,611s
    $

The culprit package was webkit2gtk3-2.40.1-1.fc36.ppc64le.rpm.

To reproduce the issue on that package, I do:

    $ time ~/git/libabigail/rhbz2273891/build/tools/abipkgdiff --self-check --suppr ~/git/libabigail/rhbz2273891/default.abignore --d1 webkit2gtk3-debuginfo-2.40.1-1.fc36.ppc64le.rpm --devel1 webkit2gtk3-devel-2.40.1-1.fc36.ppc64le.rpm webkit2gtk3-2.40.1-1.fc36.ppc64le.rpm

    ==== SELF CHECK SUCCEEDED for 'libwebkit2gtk-4.0.so.37.63.2' ====
    ==== SELF CHECK SUCCEEDED for 'WebKitWebDriver' ====
    ==== SELF CHECK SUCCEEDED for 'WebKitNetworkProcess' ====
    ==== SELF CHECK SUCCEEDED for 'WebKitWebProcess' ====

    real 8m25,895s
    user 8m46,433s
    sys         0m15,683s
    $

* default.abignore: Split the libwebkit2gtk suppression
specification for types whose names match the regexp
^std::.*|WebCore::.*|WebKit::.* into two.  One that drops type
with names being ^std::.* and another one that turns type being
WebCore::.*|WebKit::.* into opaque types.
* doc/manuals/libabigail-concepts.rst: Add documentation for the
new special label libabigail::OPAQUE_TYPE_LABEL that transforms
types matching a [suppress_type] into opaque types.
* include/abg-suppression.h (is_opaque_type_suppr_spec): Renamed
is_private_type_suppr_spec into this.
(get_opaque_types_suppr_spec_label): Renamed
get_private_types_suppr_spec_label.
* src/abg-comparison.cc (diff::is_suppressed): Adjust.
* src/abg-dwarf-reader.cc (type_is_suppressed): Adjust. Change the
name of the type_is_private parameter into type_is_opaque.
(get_opaque_version_of_type): Do not return early if the type has
no associated location.  What was I thinking.
(build_ir_node_from_die): For enums, struct and classes adjust
call to type_is_suppressed.
* src/abg-suppression.cc (type_suppression::suppresses_diff):
Adjust to using is_opaque_type_suppr_spec and
get_opaque_version_of_type in lieu of is_private_type_suppr_spec
and get_private_types_suppr_spec_label.
(get_opaque_types_suppr_spec_label): Rename
get_private_types_suppr_spec_label into this.  Also, rename the
name of the special label that specifies opaque types from
"Artificial private types suppression specification" to
"libabigail::OPAQUE_TYPE_LABEL".
(is_opaque_type_suppr_spec): Rename is_private_type_suppr_spec
into this.
(is_type_suppressed): Rename the "type_is_private" parameter into
"type_is_opaque".
* src/abg-tools-utils.cc (handle_file_entry): Adjust to using
get_opaque_types_suppr_spec_label rather than
get_private_types_suppr_spec_label.
* tools/abipkgdiff.cc (compare): Use the supprs variable where all
the suppression specifications got accumulated, not just the
priv_types_supprs1.
(compare_to_self): Add a suppression specifications variable for
private types.  Add those private types specs to the user-provided
ones.
* tools/fedabipkgdiff (abipkgdiff): In the self comparison mode,
take into account devel packages and suppression specifications.
Pass those to the abipkgdiff tool's invocation.
* tests/data/test-diff-suppr/PR31646/test-PR31646-result-[1-3].txt:
New reference test output files.
* tests/data/test-diff-suppr/PR31646/test-PR31646-v{0,1}.cc:
Source code of binary inputs below.
* tests/data/test-diff-suppr/PR31646/test-PR31646-v{0,1}.o: Binary
input files.
* tests/data/test-diff-suppr/PR31646/test-PR31646.2.abignore:
Suppression specification file.
* tests/data/test-diff-suppr/PR31646/test-PR31646.abignore:
Likewise.
* tests/data/Makefile.am: Add the new test material above to
source distribution.
* tests/test-diff-suppr.cc (in_out_specs): Add the new test input
to this harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 months agoBug 29160 - support fn symbol aliasing a var symbol
Dodji Seketeli [Wed, 3 Apr 2024 15:39:30 +0000 (17:39 +0200)]
Bug 29160 - support fn symbol aliasing a var symbol

In binaries originating from OCaml on s390x or ppcle platforms, it can
happen that a function symbol aliases a variable symbol.

By default, the ABIXML reader doesn't expect that.  It expects that
all aliases of a symbol are symbols of the same kind as their target.

This patch relaxes that constraint from the ABIXML reader.  It teaches
read_symbol_db_from_input how to resolve unresolved function (resp.
variable) symbol aliases to variable (resp. function) symbols.

* src/abg-reader.cc (typedef string_strings_map_type): Define new
typedef.
(resolve_symbol_aliases): Define new function.
(build_elf_symbol_db): Add two new parameters to carry unresolved
function and variable symbol aliases.  When a symbol alias can't
resolve to any of the symbols of its kind (function or variable)
then stage the alias away in the set of unresolved aliases.  That
set is then going to be resolved later.
(read_symbol_db_from_input): Add two new parameters to carry
unresolved function and variable symbol aliases.  Pass them down
to build_elf_symbol_db.
(reader::read_corpus): Adjust the invocation of
read_symbol_db_from_input to get the sets of unresolved function &
variable symbol aliases.  Invoke the new resolve_symbol_aliases
the unresolved function & variable aliases.
* tests/data/test-diff-pkg/PR29610/guestfs-tools-1.51.6-2.el9.s390x-self-check-report.txt:
New test reference output.
* tests/data/test-diff-pkg/PR29610/guestfs-tools-1.51.6-2.el9.s390x.rpm:
New binary test input.
* tests/data/test-diff-pkg/PR29610/guestfs-tools-debuginfo-1.51.6-2.el9.s390x.rpm:
Likewise.
* tests/data/Makefile.am: Add this new test material to source
distribution.
* tests/test-diff-pkg.cc (in_out_specs): Add the new test input to
this test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 months agoBug 31513 - Fix fallout of initial patch
Dodji Seketeli [Wed, 3 Apr 2024 09:10:38 +0000 (11:10 +0200)]
Bug 31513 - Fix fallout of initial patch

As Jianfeng Fan pointed out in a comment at
https://sourceware.org/bugzilla/show_bug.cgi?id=31513#c14, there is a
thinko in commit
https://sourceware.org/git/?p=libabigail.git;a=commit;h=338394f5454990c715b52bb4bc2ed47b39d6528b.

has_subtype_changes forgets to reset the s_member when f_member is
reset.  Both variables should be reset in tandem, just like what is
done in has_offset_changes.

Fixed thus.

* src/abg-comp-filter.cc (has_subtype_changes): Reset s_member in
the loop, just like f_member.
* tests/data/test-abidiff-exit/PR31513/non-regr/report1.txt: Adjust.
* tests/data/test-abidiff-exit/PR31513/non-regr/report2.txt: Adjust.
* tests/test-abidiff-exit.cc (in_out_specs): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 months agocomparison: Fix erroneous detection of deleted anonymous data members
Dodji Seketeli [Fri, 29 Mar 2024 11:22:06 +0000 (12:22 +0100)]
comparison: Fix erroneous detection of deleted anonymous data members

It has been reported over IRC by Robin Jarry that in some cases,
abidiff would wrongly consider anonymous data members as being
deleted.  These are cases where the anonymous data members were moved
into other anonymous data members without incurring any size or offset
change.

This patch reduces (and hopefully eliminates) false positives in
detecting anonymous data members deletion by considering the leaf data
members of the anonymous data members.

It considers that if all leaf data members contained in the previous
anonymous data members are still present in the new version of the
type, then no data member deletion occurred, basically.

The non-regression test added to this patch contains two binaries that
Robin Jarry sent me.  They were built for the source code before and
after the patch he submitted at
http://patches.dpdk.org/project/dpdk/patch/20240327091440.1166119-2-rjarry@redhat.com/.

Note that I have also added a synthetic reproducer example I came up
with after understanding the issue at hand.

* src/abg-comparison.cc
(class_or_union_diff::ensure_lookup_tables_populated): If leaf
data members of an anonymous data member are still present in the
new version of the class, then the anonymous data member cannot be
considered as being removed from the second version of the class.
* tests/data/test-abidiff-exit/non-del-anon-dm/non-regr/report0.txt:
Reference test output.
* tests/data/test-abidiff-exit/non-del-anon-dm/non-regr/test0-v{0,1}.c:
Source code of the binary input below.
* tests/data/test-abidiff-exit/non-del-anon-dm/non-regr/test0-v{0,1}.o:
New binary test input.
* tests/data/test-abidiff-exit/non-del-anon-dm/reported/binaries-origin.txt:
File mentioning the origin of the reported binary.
* tests/data/test-abidiff-exit/non-del-anon-dm/reported/librte_graph.so.24.{0,1}:
Binary test input.
* tests/data/test-abidiff-exit/non-del-anon-dm/reported/report0.txt:
Reference test output.
* tests/data/Makefile.am: Add the test material above to source
distribution.
* tests/test-abidiff-exit.cc (in_out_specs): Add test material
above to this harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 months agoBug 31513 - abidiff considers data members moved to base class as harmful
Dodji Seketeli [Thu, 28 Mar 2024 16:39:38 +0000 (17:39 +0100)]
Bug 31513 - abidiff considers data members moved to base class as harmful

Consider the 'struct type' below and its use in the file
example-v0.cc:

    //----> example-v0.cc: <------
    struct type
    {
      int m0;
    };

    int
    use(type& t)
    {
      return t.m0;
    }
    //---->8<-----

Now, consider a second version of that program where the data member
of the 'struct type' is moved into a base class:

    //----> example-v1.cc: <------
    struct base
    {
      int m0;
    };

    struct type : public base
    {
    };

    int
    use(type& t)
    {
      return t.m0;
    }
    //---->8<------

The first and second version of 'struct type' are ABI compatible
because neither the size of 'struct type' nor the offset of the data
member m0 has changed.

But then look at what abidiff says:

    $ abidiff example-v0.o example-v1.o || echo "exit code: $?"
    Functions changes summary: 0 Removed, 1 Changed, 0 Added function
    Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

    1 function with some indirect sub-type change:

      [C] 'function int use(type&)' at example-v0.cc:7:1 has some indirect sub-type changes:
parameter 1 of type 'type&' has sub-type changes:
  in referenced type 'struct type' at example-v1.cc:6:1:
    type size hasn't changed
    1 base class insertion:
      struct base at example-v1.cc:1:1
    1 data member deletion:
      'int m0', at offset 0 (in bits) at example-v0.cc:3:1

    exit code: 4
    $

abidiff considers that the mere addition of a base class constitutes a
potential ABI incompatibility.

Also, abidiff fails to see that although the data member m0 was
removed from 'struct type' itself, it was moved into its new base
type.  In practice, the data member m0 is still a member of 'struct
type', by definition of class type inheritance.

Thus, the exit code of abidiff is ABIDIFF_ABI_CHANGE which value is 4.

This patch fixes this problem.

First of all, here is what abidiff now says with this patch:

    $ abidiff example-v0.o example-v1.o && echo "return code: $?"
    Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added function
    Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

    return code: 0
    $

In other words, abidiff now recognizes the changes as being ABI
compatible and filters them out by default.

Furthermore, here are the changes that abidiff sees when asked to
avoid filtering these (now considered harmless) changes:

    $ abidiff --harmless example-v0.o example-v1.o && echo "return code: $?"
    Functions changes summary: 0 Removed, 1 Changed, 0 Added function
    Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

    1 function with some indirect sub-type change:

      [C] 'function int use(type&)' at example-v0.cc:7:1 has some indirect sub-type changes:
parameter 1 of type 'type&' has sub-type changes:
  in referenced type 'struct type' at example-v1.cc:6:1:
    type size hasn't changed
    1 base class insertion:
      struct base at example-v1.cc:1:1

    $

We can see that abidiff no longer considers that the data member m0
was deleted.

At its core, this patch teaches
class_diff::ensure_lookup_tables_populated to detect data members
being moved to base classes.  That detection prevents the code base to
consider those data members as being removed from the class.

Now that the moved data members are not considered as removed, the
patch goes further to consider data member moves to base classes that
are not accompanied with any size or offset change as being harmless,
and thus, to be filtered out by default.

To that end, the patch teaches categorize_harmful_diff_node that an
added base classes is not necessarily a harmful change if it is not
accompanied with a size or offset change.  Rather, an added base
classes (or any change to a class) not accompanied with a size or
offset change is now categorized into
HARMLESS_UNION_OR_CLASS_CHANGE_CATEGORY.  Note that the previous
HARMLESS_UNION_CHANGE_CATEGORY was renamed into
HARMLESS_UNION_OR_CLASS_CHANGE_CATEGORY.

Incidentally, a removal of a base class or any change accompanied with
an offset change is always categorized as harmful change.

The patch also adds several non-regression tests.

* include/abg-comparison.h (typedef string_decl_base_sptr_map):
Move this typedef to include/abg-fwd.h:
(HARMLESS_UNION_OR_CLASS_CHANGE_CATEGORY): Inside the enum
diff_category, rename the enumerator
HARMLESS_UNION_CHANGE_CATEGORY into this.
(EVERYTHING_CATEGORY): Adjust this enum to refer to
HARMLESS_UNION_OR_CLASS_CHANGE_CATEGORY, no more HARMLESS_UNION_CHANGE_CATEGORY
* include/abg-fwd.h (typedef string_decl_base_sptr_map): Move this
typedef here from abg-comparison.h
(collect_non_anonymous_data_members): Declare new function.
* src/abg-comp-filter.cc (has_offset_changes)
(type_has_offset_changes, has_offset_changes)
(has_subtype_changes, class_diff_has_only_harmless_changes):
Define new static functions.
(base_classes_removed): Rename base_classes_added_or_removed into
this and update comment.
(categorize_harmless_diff_node): Changes that were categorized as
HARMLESS_UNION_CHANGE_CATEGORY is now categorized as
HARMLESS_UNION_OR_CLASS_CHANGE_CATEGORY.  Also, a diff that
satisfies either union_diff_has_harmless_changes or
class_diff_has_only_harmless_changes is categorized as
HARMLESS_UNION_OR_CLASS_CHANGE_CATEGORY.
(categorize_harmful_diff_node): Adjust to invoke
base_classes_removed instead of base_classes_added_or_removed.  An
added base class doesn't necessarily qualifies as a harmful change
anymore.  Rather, a diff node that carries an offset change as
detected by type_has_offset_changes is categorized as
SIZE_OR_OFFSET_CHANGE_CATEGORY.
* src/abg-comparison.cc (get_default_harmless_categories_bitmap):
Adjust to use
abigail::comparison::HARMLESS_UNION_OR_CLASS_CHANGE_CATEGORY
rather than abigail::comparison::HARMLESS_UNION_CHANGE_CATEGORY.
(operator<<(ostream& o, diff_category c)): Likewise.
(class_diff::ensure_lookup_tables_populated): Detect data members
that are moved into base classes to avoid considering those data
members as being removed from the class.
* src/abg-default-reporter.cc (default_reporter::report): Adjust
to use HARMLESS_UNION_OR_CLASS_CHANGE_CATEGORY rather than
HARMLESS_UNION_CHANGE_CATEGORY.
* src/abg-ir.cc (collect_non_anonymous_data_members): Define
function overloads.
* tests/data/test-abidiff-exit/PR31513/non-regr/libtest[1-4]-v{0,1}.so:
New binary test input files.
* tests/data/test-abidiff-exit/PR31513/non-regr/report[1-4.txt:
New reference output files.
* tests/data/test-abidiff-exit/PR31513/non-regr/test[1-4]-v{0,1}.cc:
Source code of the binary input files above.
* tests/data/test-abidiff-exit/PR31513/reported/PR31513-reported-report-{1,2}.txt:
New reference output files.
* tests/data/test-abidiff-exit/PR31513/reported/libloremipsum_gcc{7,11}.so:
New binary test input files.
* tests/data/test-abidiff-exit/PR31513/reported/libstdcpp.suppr:
New test suppression file.
* tests/data/Makefile.am: Add new test files above to source
distribution.
* tests/test-abidiff-exit.cc (in_out_specs): Add the new input
test files to this test harness.
* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt:
Adjust.
* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 months agoabidiff: Fix indentation of help string
Dodji Seketeli [Thu, 28 Mar 2024 16:34:33 +0000 (17:34 +0100)]
abidiff: Fix indentation of help string

* tools/abidiff.cc (display_usage): Fix indentation of help string

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 months agosuppression: Fix indentation
Dodji Seketeli [Fri, 29 Mar 2024 11:58:33 +0000 (12:58 +0100)]
suppression: Fix indentation

* src/abg-suppression.cc
(function_suppression::suppresses_function_symbol): Fix
indentation.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 months agocomparison: Fix typo
Dodji Seketeli [Thu, 28 Mar 2024 16:31:05 +0000 (17:31 +0100)]
comparison: Fix typo

* src/abg-comparison.cc
(class_or_union_diff::ensure_lookup_tables_populated): Fix a
comment typo.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 months agoir: Fix Emacs C++ mode header
Dodji Seketeli [Thu, 28 Mar 2024 16:33:27 +0000 (17:33 +0100)]
ir: Fix Emacs C++ mode header

* src/abg-ir.cc: Fix the Emacs C++ mode header.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 months agoabidb: drop the TODO items from the python script
Frank Ch. Eigler [Fri, 22 Mar 2024 18:13:10 +0000 (14:13 -0400)]
abidb: drop the TODO items from the python script

Instead they've moved over to sourceware bugzilla.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
8 months agoabidb: Introduce a tool to manage the ABI of a Linux distribution
Frank Ch. Eigler [Tue, 5 Dec 2023 15:42:44 +0000 (10:42 -0500)]
abidb: Introduce a tool to manage the ABI of a Linux distribution

This patch introduces a new tool named abidb.  It manages a Git
repository of the Application Binary Interfaces of a set of shared
libraries.  Those ABIs are stored in the Git repository in the form of
ABIXML files.

The tool then supports the verification of the ABI compatibility of a
given binary against the stored ABIs of shared libraries.

* configure.ac: Condition building abidb on the presence of python
and the required modules.
* doc/manuals/Makefile.am: Add the abidb.rst documentation to
source distribution.  Distribute the abidb.1 manpage file as well.
* doc/manuals/abidb.rst: New documentation file.
* doc/manuals/conf.py: Configure the generation of the abidb.1
manage from the abidb.rst file above.
* doc/manuals/libabigail-tools.rst: Add a reference to the new
abidb tool.
* tests/Makefile.am: Register runabidb1.sh and runabidb2.sh as
tests for abidb.  Register runabidb1.sh.in and runabidb2.sh.in as
input files for autoconf generated runabidb1.sh and runabidb2.sh.
* tests/data/Makefile.am: Add abidb2client.c, abidb2so.c and
abidb2soBAD.c to source distribution.
* tests/data/abidb2client.c: New source file for test input binaries.
* tests/data/abidb2so.c: Likewise.
* tests/data/abidb2soBAD.c: Likewise.
* tests/runtestabidb1.sh.in: New test script input for autoconf generation.
* tests/runtestabidb2.sh.in: Likewise.
* tools/Makefile.am: Add the new abidb tool to the set of tools.
* tools/abidb: The New Tool, ladies and gentlemen!

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoabicompat: Fix exit code in weak mode
Dodji Seketeli [Fri, 15 Mar 2024 16:03:14 +0000 (17:03 +0100)]
abicompat: Fix exit code in weak mode

It turns out the tool is almost always returning ABIDIFF_OK in weak
mode.  Oops.  Fixed thus.  Also, update the test-abicompat.cc to test
for expected exit codes to catch this kind of regressions in the
future.

* tools/abicompat.cc (perform_compat_check_in_weak_mode): Do not
override the status code when doing the comparison in the reverse
direction.
(compare_expected_against_provided_functions)
(compare_expected_against_provided_variables): Set the status code
close to the detected diff.  In the future, this might help us
provide finer grained status.
* tests/test-abicompat.cc (InOutSpec::status): Add a new data
member to represent the expected exit code.
(in_out_specs): Adjust the array of tests.
(main): If the actual exit code is different from the expected
one, then the test failed so let's report it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoEmit & read undefined interfaces to & from ABIXML
Dodji Seketeli [Fri, 8 Mar 2024 14:31:44 +0000 (15:31 +0100)]
Emit & read undefined interfaces to & from ABIXML

This patch teaches the ABIXML writer to emit information about
undefined interfaces.  It also teaches the ABIXML reader to read
information about undefined interfaces.

It introduces two new ABIXML elements:
'undefined-elf-function-symbols' and 'undefined-elf-variable-symbols'
to represent undefined function and variable symbols.

Then, in the 'abi-instr' element functions and variables that
reference undefined elf symbols now have an 'elf-symbol-id' attribute
referencing the undefined symbol listed in the new
'undefined-elf-variable-symbols' or 'undefined-elf-function-symbols'
element.

The patch introduces tests that perform compatibility checks done on
ABIXML files.

* include/abg-writer.h (set_write_undefined_symbols): Declare new
function.
(set_common_options): Use the new set_write_undefined_symbols in
this function template.
* src/abg-dwarf-reader.cc (reader::{get_die_language, die_is_in_c,
die_is_in_cplus_plus, die_is_in_c_or_cplusplus}): Move these
member functions into ...
(get_die_language, die_is_in_c, die_is_in_cplus_plus)
(die_is_in_c_or_cplusplus): ... these static non-member functions.
(fn_die_equal_by_linkage_name): Adjust and remove the now useless
reader parameter.
(compare_dies, get_scope_die, function_is_suppressed)
(variable_is_suppressed): Adjust.
(build_translation_unit_and_add_to_ir): When we are asked to load
undefined symbol, make sure to also analyze top-level class types
and if we are in C++, also analyze top-level unions and structs as
these might also have some undefined interfaces.
* src/abg-reader.cc (build_elf_symbol_db): Let's not construct and
return the symbol DB anymore.  Rather, let's let the caller
construct it, so we can just update it with the input gathered.
(read_symbol_db_from_input): Support getting undefined function
and variable symbols from the new undefined-elf-function-symbols
and undefined-elf-variable-symbols elements.  Note that undefined
and defined function symbols go into the same symbol DB whereas
undefined and defined variable symbols go into another symbol DB.
Now, we suppose that the variable & symbol DBs are allocated by
the caller.  We pass it down to build_elf_symbol_db that populates
it.  Maybe we should rename build_elf_symbol_db into
populate_elf_symbol_db.
(reader::read_corpus): Allocate the function
and variable symbol DB and let read_symbol_db_from_input populate
it.  Sort functions and variables after reading the whole ABIXML.
* src/abg-writer.cc (write_context::write_context): Define new
data member.
(write_context::write_context): Initialize it.
(write_context::{get,set}::write_undefined_symbols): Define
accessors.
(set_write_undefined_symbols): Define a new function.
(write_context::decl_is_emitted): Add a new overload.
(write_elf_symbol_reference): Add a writer context and a corpus
parameter.  If the symbol is not in the corpus or if the symbol is
undefined and we were not asked to emit undefined symbols then do
not emit any reference to it.
(write_translation_unit): Emit the undefined functions and
variables that belong to the current translation unit, along with
their reference to the undefined ELF symbol they are associated
to.
(write_var_decl, write_function_decl): Let
write_elf_symbol_reference decide whether it should emit the
reference to ELF symbol or not, as it now know how to make that
decision.
(write_corpus): Write the undefined function & variable ELF symbol
data bases.  These in the new 'undefined-elf-function-symbols' and
'undefined-elf-variable-symbols' elements.
* tools/abidw.cc (options::load_undefined_interfaces): Define new
data member.
(options:options): Initialize it.
(display_usage): Add a help string for the
--no-load-undefined-interfaces option.
(parse_command_line): Parse the --no-load-undefined-interfaces
option.
(set_generic_options): Set the
fe_iface::option_type::load_undefined_interfaces option.
* doc/manuals/abidw.rst: Document the new
--no-load-undefined-interfaces of abidw.
* tests/data/test-abicompat/test10/libtest10-with-exported-symbols.so:
New binary input file.
* tests/data/test-abicompat/test10/libtest10-with-incompatible-exported-symbols.so:
New binary input file.
* tests/data/test-abicompat/test10/libtest10-with-incompatible-exported-symbols.so.abi:
New abixml input file.
* tests/data/test-abicompat/test10/test10-app-with-undefined-symbols:
New binary input file.
* tests/data/test-abicompat/test10/test10-app-with-undefined-symbols.abi:
New abixml input file.
* tests/data/test-abicompat/test10/test10-app-with-undefined-symbols.cc:
New source file for binary test input
* tests/data/test-abicompat/test10/test10-fn-changed-report-0.txt:
New source file for binary test input
* tests/data/test-abicompat/test10/test10-fn-changed-report-1.txt:
New source file for binary test input
* tests/data/test-abicompat/test10/test10-fn-changed-report-2.txt:
New source file for binary test input
* tests/data/test-abicompat/test10/test10-fn-changed-report-3.txt:
New source file for binary test input
* tests/data/test-abicompat/test10/test10-fn-changed-report-4.txt:
New source file for binary test input
* tests/data/test-abicompat/test10/test10-with-exported-symbols.cc:
New source file for binary test input
* tests/data/test-abicompat/test10/test10-with-exported-symbols.h:
New source file for binary test input
* tests/data/test-abicompat/test10/test10-with-incompatible-exported-symbols.cc:
New source file for binary test input
* tests/data/test-abicompat/test10/test10-with-incompatible-exported-symbols.h:
New source file for binary test input.
* tests/data/Makefile.am: Add new test input files to source
distribution.
* tests/test-abicompat.cc (in_out_specs): Add the new test inputs
to this test harness.
* tests/test-annotate.cc (main): Use the new
--no-load-undefined-interfaces option of abidw to keep the old
behavior.
* tests/test-read-common.cc (test_task::serialize_corpus): Do not
emit undefined symbols.
* tests/test-read-dwarf.cc (test_task_dwarf::perform): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoAdd support for undefined symbols in the BTF reader
Dodji Seketeli [Tue, 12 Mar 2024 16:17:16 +0000 (17:17 +0100)]
Add support for undefined symbols in the BTF reader

This patch teaches the BTF reader how to construct an IR for undefined
interfaces.  The patch also updates the abicompat tool for BTF
support.

* doc/manuals/abicompat.rst: Update documentation for the --btf
option of abicompat.
* include/abg-elf-reader.h
(elf::reader::{function,variable}_symbol_is_undefined): Declare
new member functions.
* src/abg-btf-reader.cc
(reader::read_debug_info_into_corpus): Sort functions &
variables after canonicalization.
(reader::build_ir_node_from_btf_type): Always call
fe_iface::add_{fn,var}_to_exported_or_undefined_decls with the
decl that was constructed.
(reader::build_function_decl): Support setting an undefined symbol
to the function decl.
(reader::build_var_decl): Likewise, support setting undefined
symbol the variable decl.
* src/abg-elf-reader.cc
((elf::reader::{function,variable}_symbol_is_undefined): Declare
new member functions.): Define new member functions.
* src/abg-symtab-reader.cc
(symtab::{function,variable}_symbol_is_undefined): Return the
undefined symbol that was found.
* src/abg-symtab-reader.h
(symtab::{function,variable}_symbol_is_undefined): Return an
undefined symbol rather than just a boolean value.
* tools/abicompat.cc: Add support for BTF here.
(options::use_btf): Define new data member ...
(options::options): ... and initialize it.
(display_usage): Add a help string for the --btf option.
(parse_command_line): Parse the --btf option.
* tests/data/test-abicompat/test7-fn-changed-report-0.1.txt: New
reference test output file.
* tests/data/test-abicompat/test7-fn-changed-report-2.1.txt:
Likewise.
* tests/data/test-abicompat/libtest7-fn-changed-libapp-btf-v0.so:
New binary input file.
* tests/data/test-abicompat/libtest7-fn-changed-libapp-btf-v1.so:
Likewise.
* tests/data/test-abicompat/test7-fn-changed-app.btf: Likewise.
* tests/data/Makefile.am: Add the new test material to source
distribution.
* tests/test-abicompat.cc (in_out_specs): Add the new test input
to the test harness.
* tests/data/test-abicompat/test7-fn-changed-app.c: Adjust.
* tests/data/test-abicompat/test7-fn-changed-libapp-v0.c:
Likewise.
* tests/data/test-abicompat/test7-fn-changed-libapp-v1.c: Likewise

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoFactorize elf-reader::{variable,function}_symbol_is_exported into symtab
Dodji Seketeli [Tue, 12 Mar 2024 15:01:30 +0000 (16:01 +0100)]
Factorize elf-reader::{variable,function}_symbol_is_exported into symtab

Move the code of elf-reader::{variable,function}_symbol_is_exported into
symtab::{variable,function}_symbol_is_exported (where it belongs) and
make the former use the later.

* src/abg-elf-reader.cc (reader::function_symbol_is_exported): Use
the new symtab::function_symbol_is_exported.
(reader::variable_symbol_is_exported): Use the new
symtab::variable_symbol_is_exported.
* src/abg-symtab-reader.cc
(symtab::{function,variable}_symbol_is_exported): Factorize
elf::reader::{function,variable}_symbol_is_exported into this.
* src/abg-symtab-reader.h
(symtab::{function,variable}_symbol_is_exported): Declare new
member functions.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoRepresent undefined corpus interfaces to analyze app compatibility
Dodji Seketeli [Wed, 21 Feb 2024 09:54:57 +0000 (10:54 +0100)]
Represent undefined corpus interfaces to analyze app compatibility

In the text below, the term interface means the "declaration of either
a function or a global variable".

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

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

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

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

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

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

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

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

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agotools-utils.cc: Fix potential crash when testing for CTF debug info
Dodji Seketeli [Wed, 13 Mar 2024 10:18:11 +0000 (11:18 +0100)]
tools-utils.cc: Fix potential crash when testing for CTF debug info

When looking at something else, I stumbled upon a crash when testing
for the presence of CTF debug info.

* src/abg-tools-utils.cc (file_has_ctf_debug_info): Do not crash
on empty debug info paths.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoabidw: Add a -o short option for --out-file
Dodji Seketeli [Fri, 8 Mar 2024 10:34:40 +0000 (11:34 +0100)]
abidw: Add a -o short option for --out-file

* doc/manuals/abidw.rst: Document the -o option.
* tools/abidw.cc (display_usage): Update doc string for the
--out-file|-o option.
(parse_command): Support the -o short option.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agodwarf-reader: Support creating functions from DW_TAG_inlined_subroutine
Dodji Seketeli [Fri, 8 Mar 2024 14:25:18 +0000 (15:25 +0100)]
dwarf-reader: Support creating functions from DW_TAG_inlined_subroutine

Update the assert in build_function_decl to work on
DW_TAG_inlined_subroutine DIEs.

* src/abg-dwarf-reader.cc (build_function_decl): Loosen the assert
to accept DW_TAG_inlined_subroutine DIEs.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoir,dwarf-reader: Peel const-qualifier from const this pointers
Dodji Seketeli [Tue, 5 Mar 2024 15:52:44 +0000 (16:52 +0100)]
ir,dwarf-reader: Peel const-qualifier from const this pointers

In DWARF, it appears that the this pointer of a concrete instance of
method is sometimes represented as a const pointer, whereas the this
pointer of the abstract instance (or interface) of that same method
has the this pointer represented as a non-const pointer.  That
difference often causes some spurious const-ness change reports on the
this pointer when doing comparisons.

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

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

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agocomparison: Better sort function difference report
Dodji Seketeli [Mon, 4 Mar 2024 09:44:16 +0000 (10:44 +0100)]
comparison: Better sort function difference report

Looking at the result of builds on various platforms, it appears that
the order of the method change reports in the
test29-vtable-changes-report-0.txt of runtestdiffdwarf was not stable
across all platforms. debian-armhf was exhibiting this change in
output, for instance:

    --- /var/lib/buildbot/workers/wildebeest/libabigail-try-debian-armhf/build/tests/data/test-diff-dwarf/test29-vtable-changes-report-0.txt
2024-03-04 08:56:42.307366590 +0000
    +++ /var/lib/buildbot/workers/wildebeest/libabigail-try-debian-armhf/build/tests/output/test-diff-dwarf/test29-vtable-changes-report-0.txt
2024-03-04 09:20:22.146334907 +0000
    @@ -19,13 +19,13 @@
 implicit parameter 0 of type 'S* const' has sub-type
changes:
   in unqualified underlying type 'S*':
     pointed to type 'struct S' changed, as being reported
    +          'method virtual S::~S(int)' has some sub-type changes:
    +            implicit parameter 0 of type 'S*' has sub-type changes:
    +              pointed to type 'struct S' changed, as being reported
       'method virtual S::~S()' has some sub-type changes:
 implicit parameter 0 of type 'S* const' has sub-type
changes:
   in unqualified underlying type 'S*':
     pointed to type 'struct S' changed, as being reported
    -          'method virtual S::~S(int)' has some sub-type changes:
    -            implicit parameter 0 of type 'S*' has sub-type changes:
    -              pointed to type 'struct S' changed, as being reported
       'method virtual void S::fn0()' has some sub-type changes:
 implicit parameter 0 of type 'S*' has sub-type changes:
   pointed to type 'struct S' changed, as being reported

Better handling the sorting of function changes should hopefully fix
this issue.

* src/abg-comparison-priv.h (is_less_than): Declare new helper
function.
(function_decl_diff_comp::operator(const function_decl_diff&,
                                   const function_decl_diff&)):
Use it here.
(virtual_member_function_diff_comp::operator(const function_decl_diff&,
                                             const function_decl_diff&)):
Likewise.
* tests/data/test-abidiff/test-PR18791-report0.txt: Adjust.
* tests/data/test-diff-dwarf/test29-vtable-changes-report-0.txt:
Adjust.
* tests/data/test-diff-dwarf/test30-vtable-changes-report-0.txt:
Adjust.
* tests/data/test-diff-dwarf/test31-vtable-changes-report-0.txt:
Adjust.
* tests/data/test-diff-dwarf/test41-PR20476-hidden-report-0.txt:
Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoir,dwarf-reader: Better handle inline-ness setting or detection
Dodji Seketeli [Mon, 4 Mar 2024 08:34:51 +0000 (09:34 +0100)]
ir,dwarf-reader: Better handle inline-ness setting or detection

The DWARF reader mistakenly considers that if the value of
DW_AT_inline attribute is set to DW_INL_declared_inlined, that means
the function we are looking at was declared inline.  Rather, that
means the function was declared inlined *and* was inlined by the
compiler.  To have a better coverage of functions that were declared
inline, we need to consider functions which DW_AT_inline attribute is
set to DW_INL_declared_inlined or DW_INL_declared_not_inlined.  This
patches fixes that.

I noticed that we were missing concrete instances of inlined functions
as we were taking into account DW_TAG_inlined_subroutine DIEs.  This
patch fixes that.

I noticed that finish_member_function_reading (which is called for
virtual member functions that don't have associated an associated elf
symbol in the current translation unit) wasn't taking into account the
inline declaration of virtual member functions.  This patch fixes that.

Last but not least, this patch stops considering the change of
inline-ness declaration of functions as being an ABI change.  Whenever
that inline-ness declaration change happens alongside a meaningful ABI
change, libabigail will report it, but that alone is not an ABI
change.

All in all, these change fix the fall-out (caught by the CI) from the
previous patch:
3ccfe465 dwarf-reader: Fix DIE origin handling & scope getting

* include/abg-ir.h (function_decl::is_declared_inline): Add a
setter overload.
* src/abg-dwarf-reader.cc (die_is_declared_inline): Take into the
account values DW_INL_declared_inlined and
DW_INL_declared_not_inlined of DW_AT_inline attribute.  Not just
DW_INL_declared_inlined.
(finish_member_function_reading): Set the inline-ness declaration
here.
(build_ir_node_from_die): Handle DW_TAG_inlined_subroutine just as
DW_TAG_subprogram.
* src/abg-ir.cc (function_decl::is_declared_inline): Add a setter
overload.
* tests/data/test-annotate/test1.abi: Adjust.
* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
Likewise.
* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
Likewise.
* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi:
Likewise.
* tests/data/test-diff-dwarf/test42-PR21296-clanggcc-report0.txt:
Likewise.
* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
* tests/data/test-read-dwarf/test1.abi: Likewise.
* tests/data/test-read-dwarf/test1.hash.abi: Likewise.
* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise.
* tests/data/test-read-dwarf/test11-pr18828.so.abi: Likewise.
* tests/data/test-read-dwarf/test14-pr18893.so.abi: Likewise.
* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
* tests/data/test-read-dwarf/test17-pr19027.so.abi: Likewise.
* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
Likewise.
* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
Likewise.
* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
Likewise.
* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agotests/data/test-diff-pkg: Update dpkg related reference output
Dodji Seketeli [Sat, 2 Mar 2024 15:30:23 +0000 (16:30 +0100)]
tests/data/test-diff-pkg: Update dpkg related reference output

The previous patch needed the update of a lot of reference tests.  I
didn't have dpkg installed on my development box so I missed updating
dpkg-related reference output.

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

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agodwarf-reader: Fix DIE origin handling & scope getting users/dodji/pre-abidb-patches
Dodji Seketeli [Wed, 28 Feb 2024 10:14:11 +0000 (11:14 +0100)]
dwarf-reader: Fix DIE origin handling & scope getting

While looking at something else, I noticed that a number of times the
code to create the IR for function-decl was adding the function to the
wrong scope, especially for DIEs that had a chain of
DW_AT_abstract_origin *and* DW_AT_specification attributes.

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

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

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

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

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agodwarf-reader, ir: Add member fns to exported corpus fns after c14n
Dodji Seketeli [Tue, 27 Feb 2024 15:45:28 +0000 (16:45 +0100)]
dwarf-reader, ir: Add member fns to exported corpus fns after c14n

There are cases where a member function C::f has a defined & exported
ELF symbol in a translation unit TU-2, whereas it has no associated
symbol in another translation unit TU-1.

The class C from TU-1 and the class C from TU-2 have the same
canonical type because they are equivalent.  Now, suppose it's C from
TU-2 that is the canonical type; that means the canonical type of C
from TU-1 is C from TU-2.

Today, the only types that are emitted in an ABIXML file are canonical
types.  So if we want the C::f which has a publicly defined & exported
elf symbol to be emitted in the ABIXML file, then the C::f that is
defined & exported in the ABI corpus should be the C::f from the
canonical class type C i.e, the C::f from TU-2.

In other words, the exported C::f should be the member function of the
canonical type class C.

That means that determining which C::f to export in the ABI corpus
should be done *after* type canonicalization.

Today however, determining which C::f to export is done during the
construction of the IR, in the DWARF reader.  That leads to
cases where the exported C::f is the one that has no defined &
exported ELF symbol.  As virtual member functions (in particular) are
involved in class type comparison, that could lead to spurious type
changes left and right.  Oops.

This patch implements the export of member functions after type
canonicalization in the DWARF reader.  Note that CTF and BTF readers
are not impacted as they only support the C language which doesn't
have member functions.

* src/abg-dwarf-reader.cc
(reader::fixup_functions_with_no_symbols): Do not export the
virtual member function here.
(build_ir_node_from_die): For DW_TAG_subprogram DIEs, likewise.
* src/abg-ir.cc (maybe_adjust_canonical_type): Walk the member
functions of the canonical type and export them in the ABI corpus
if they have a defined and exported elf symbol.
* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoir: Use linkage name to sort virtual function members
Dodji Seketeli [Tue, 27 Feb 2024 16:56:28 +0000 (17:56 +0100)]
ir: Use linkage name to sort virtual function members

There is some instability in the abixml output whenever two virtual
member functions have the same vtable offset and different mangling
name.  This patch takes the mangling into account.

* src/abg-ir.cc (virtual_member_function_less_than::operator()):
Take the linkage name into account during sorting before taking
into account the presence of elf symbols.
* tests/data/test-read-dwarf/test12-pr18844.so.abi: Adjust.
* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoabicompat: Port this to the multi-front-end architecture
Dodji Seketeli [Wed, 21 Feb 2024 09:11:01 +0000 (10:11 +0100)]
abicompat: Port this to the multi-front-end architecture

I forgot to port abicompat to the multi-front-end architecture that
was put in place a while ago.  Namely, all the other tools now use
abigail::tools_utils::create_best_elf_based_reader to create the best
elf-based reader depending on if they are given DWARF, BTF or CTF
debug information.

This patch make abicompat use
abigail::tools_utils::create_best_elf_based_reader too.

* tools/abicompat.cc (read_corpus): Use
abigail::tools_utils::create_best_elf_based_reader to create the
right reader depending on the debug information at hand.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoir,corpus,comparison: Const-iffy the access to corpus interfaces
Dodji Seketeli [Tue, 20 Feb 2024 16:05:48 +0000 (17:05 +0100)]
ir,corpus,comparison: Const-iffy the access to corpus interfaces

In preparation to subsequent patches that perform manipulations of the
corpus interfaces, it appears that we need to add const access to
those corpus interfaces.

* include/abg-comparison.h (typedef string_function_ptr_map): Make
this typedef use a const function_decl*, not just a
function_decl*.
(typedef string_var_ptr_map): Make this typedef use a const
var_decl*, not just a var_decl*.
* include/abg-corpus.h (typedef corpus::functions): Make this
typedef be a vector<const function_decl*>, not just a
vector<function_decl*>.
(corpus::exported_decls_builder::fn_id_maps_to_several_fns):
Adjust declaration to const function_decl*.
* include/abg-fwd.h (typedef istring_var_decl_ptr_map_type)
(typedef istring_function_decl_ptr_map_type): Move these typedefs to
abg-ir.h.
(get_function_id_or_pretty_representation): Use const function_decl*.
* include/abg-ir.h (typedef istring_var_decl_ptr_map_type)
(typedef istring_function_decl_ptr_map_type): Move these here from
abg-fwd.h.  Also make these use const var_decl* and const.
function_decl.
* src/abg-comparison-priv.h (sort_string_function_ptr_map)
(sort_string_var_ptr_map): Use vector<const function_decl*> and
vector<const var_decl*> rather than their non-const variants.
* src/abg-comparison.cc (sort_string_function_ptr_map)
(sort_string_var_ptr_map): Likewise.
(corpus_diff::priv::{ensure_lookup_tables_populated,
apply_supprs_to_added_removed_fns_vars_unreachable_types}):
Adjust.
* src/abg-corpus-priv.h (corpus::priv::{fns,vars}): Make these
data members use vector<const function_decl*> and vector<const
var_decl*> types.
* src/abg-corpus.cc
(corpus::exported_decls_builder::fn_id_maps_to_several_fns)
(corpus::maybe_drop_some_exported_decls): Adjust.
(corpus_group::priv::{fns,vars}): Make these data members use
vector<const function_decl*> and vector<const var_decl*> types.
* src/abg-default-reporter.cc (default_reporter::report): In the
overload for const corpus_diff&, adjust.
* src/abg-ir.cc (get_function_id_or_pretty_representation):
Adjust.
* src/abg-leaf-reporter.cc (leaf_reporter::report): In the
overload for const corpus_diff&, adjust.
* tools/abicompat.cc (perform_compat_check_in_normal_mode):
Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agoir: Fix indentation
Dodji Seketeli [Wed, 28 Feb 2024 12:40:14 +0000 (13:40 +0100)]
ir: Fix indentation

* src/abg-ir.cc (function_decl::clone): Fix indentation.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agotest-abicomat.cc: Don't show details about PASSing tests.
Dodji Seketeli [Wed, 28 Feb 2024 12:32:00 +0000 (13:32 +0100)]
test-abicomat.cc: Don't show details about PASSing tests.

While looking at something else, I noticed that this test was emitting
details about the tests that PASS, cluttering the output a lot.  Fixed
thus.

* tests/test-abicompat.cc (main): Don,'t emit details for PASSed
tests.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 months agotest-alt-dwarf-file.cc: Fix test result accounting
Dodji Seketeli [Wed, 28 Feb 2024 10:14:28 +0000 (11:14 +0100)]
test-alt-dwarf-file.cc: Fix test result accounting

The first test to fail was causing all subsequent tests to appear as
failing as well.  Fixed thus.

* tests/test-alt-dwarf-file.cc (main): Re-set the is_ok variable
to true in the loop.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This page took 0.127229 seconds and 5 git commands to generate.