Commit Graph

2512 Commits

Author SHA1 Message Date
Ben Woodard
d7557e8c25 Add github actions to support workflows
To facilitate collaboration with developers working on the BUILD-SI
project who are using github, I have been maintaining a clone of the
libabigail repo there. Having this repo also allows us to leverage
some of the tooling that github provides, in particular the ability to
have github actions test patches to verify that the builds succeed,
and all the regression tests run successfully. This will allow it to
better integrate with the normal agile workflow used by at least this
community of developers.

	* .github/workflows/build-container.yaml: New file.
	* .github/workflows/libabigail.yaml: Likewise.
	* .github/workflows/test.yaml: Likewise.
	* .github/workflows/test-fedora.yaml: Likewise.
	* .github/README.md: Likewise.
	* docker/Dockerfile.fedora: Likewise.
	* docker/Dockerfile.ubuntu: Likewise.
	* docker/Dockerfile.fedora-base: Likewise.
	* docker/Dockerfile.test: Likewise.
	* README-DOCKER.md: Likewise.

Signed-off-by: Vanessa Sochat <sochat1@llnl.gov>
Reviewed-by: Ben Woodard <woodard@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-17 00:13:40 +02:00
Guillermo E. Martinez
28a629347f abipkgdiff: Add support to compare packages with CTF debug format
This patch add support in `abipkgdiff' to compare binaries with CTF
debug information inside of packages, when `--ctf' option is provided.

	* tools/abipkgdiff.cc: Include `abg-ctf-reader.h'.
	(options::use_ctf): Add new data member.
	(display_usage): Add `--ctf' usage.
	(compare): Add condition to use ctf-reader to extract
	(parse_command_line): Set `options::use_ctf' when --ctf
	option is provided.
	and build CTF corpora when `options::use_ctf' is set.
	(compare_to_self): Likewise.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-16 18:07:40 +02:00
Guillermo E. Martinez
00a9ce61fc ctf-reader: CTF debug info for some symbols is not found
Running `abidw --ctf' tool for some executable ELF files, seems that ctf
reader is unable to get debug information for some symbols so, they will
not be neither the corpus nor in abixml file. This is happening because
internally the reader uses `ctf_arc_bufopen' expecting as argument the
sections: symbol table (.dynsym) and string table (.dynstr) for ELF
types: ET_{EXEC,DYN}, currently those sections are read by `elf_helpers'
but it uses .symtab  when it is present and `symtab_shdr->sh_link' to
get .strtab, instead.

	* src/abg-ctf-reader.cc (read_context::is_elf_exec): Remove
	data member.
	(ctf_reader::process_ctf_qualified_type): Add condition to avoid
	use qualifier in functions.
	(ctf_reader::process_ctf_archive): Use `ctf_lookup_by_symbol_name'
	to find debug information when `ctf_lookup_variable' was not
	lucky iff `corpus::CTF_ORIGIN'.
	(ctf_reader::slurp_elf_info): Use `elf_helpers::find_section_by_name'
	to read .dynsym and .dynstr when {EXEC,DYN}.
	* src/abg-elf-helpers.h (elf_helpers::find_section_by_name): Add new
	declaration.
	* src/abg-elf-helpers.cc (elf_helpers::find_section_by_name): Add new
	definition.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-13 14:34:47 +02:00
Guillermo E. Martinez
a846964b0b ctf-reader: shows incomplete summary changes
During corpus comparison with ctf support, summary changes for functions
and variables are shown like to the binaries doesn't have ctf debug
information, even though they were compiled with '-gctf' compiler
modifier, e.g:

2 Removed function symbols not referenced by debug info:

  [D] elf32_test_main@@ELFUTILS_1.7
  [D] elf64_test_main@@ELFUTILS_1.7

So, expected changes summary should be:

2 Removed functions:

  [D] 'function long int elf32_test_main()'    {elf32_test_main@@ELFUTILS_1.7}
  [D] 'function long int elf64_test_main()'    {elf64_test_main@@ELFUTILS_1.7}

	* src/abg-ctf-reader.cc (read_context::exported_decls_builder_):
	Add new data member.
	(read_context::exported_decls_builder): Add new get/set member functions.
	(read_context::maybe_add_{fn,var}_to_exported_decls): Likewise.
	(read_context::initialize): Initialize exported_decls_builder_ member.
	(read_context::build_ir_node_for_variadic_parameter_type): Add new function.
	(read_context::process_ctf_function_type): Add additional code to handle
	function's variadic parameter.
	(read_context::process_ctf_archive): Rename variable for clarity
	from `ctf_var_type' to `ctf_sym_type', using new member functions
	`maybe_add_{fn,var}_to_exported_decls'.
	(read_context::read_corpus): Set `exported_decls_builder'.
	* tests/test-read-common.cc (test_task::run_abidw): Fix error message.
	* tests/data/test-read-ctf/test-PR26568-1.o.abi: Adjust test case.
	* tests/data/test-read-ctf/test-PR26568-2.o.abi: Likewise.
	* tests/data/test-read-ctf/test-anonymous-fields.o.abi Likewise.
	* tests/data/test-read-ctf/test5.o.abi: Likewise.
	* tests/data/test-read-ctf/test7.o.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-13 14:08:28 +02:00
Frederic Cambus
c70dfec08f Fix numbering error in the abidiff manual.
* doc/manuals/abidiff.rst: Fix numbering error for the
	--headers-dir2 option.

Signed-off-by: Frederic Cambus <fred@statdns.com>
2022-05-13 13:54:31 +02:00
Guillermo E. Martinez
e64d32bee3 ctf-reader: Add support to read CTF information from the Linux Kernel
This patch is meant to extract ABI information from the CTF data
stored in the Linux kernel build directory.  It depends on the
vmlinux.ctfa archive file.

In order to generate the CTF information, the Linux Kernel build
system must support the 'make ctf' command, which causes the compiler
to be run with -gctf, thus emitting the CTF information for the
Kernel.

The target 'ctf' in the Linux Makefile generates a 'vmlinux.ctfa' file
that will be used by the ctf reader in libabigail. The 'vmlinux.ctfa'
archive has multiple 'ctf dictionaries' called "CTF archive members".

There is one CTF archive member for built-in kernel modules (in
`vmlinux') and one for each out-of-tree kernel module organized in a
parent-child hierarchy.

There is also a CTF archive member called `shared_ctf' which is a
parent dictionary containing shared symbols and CTF types used by more
than one kernel object.  These common types are stored in 'types_map'
in the ctf reader, ignoring the ctf dictionary name.  The CTF API has
the machinery for looking for a shared type in the parent dictionary
referred to in a given child dictionary. This CTF layout can be dumped
by using the objdump tool.

Due to the fact that the _same_ ctf archive is used to build the
vmlinux corpus the corpora of the kernel module (which, by the way,
all belong to the same corpus group), the high number of open/close on
the CTF archive is very time consuming during the ctf extraction.

So, the performance is improved up to 300% (from ~2m:50s to ~50s) by
keeping the ctf archive open for a given group, and thus, by using the
same ctf_archive_t pointer while building all the various corpora.

We just invoke `reset_read_context' for each new corpus.  Note that
the `read_context::ctfa` data member should be updated if the
corpus::origin data member is set to `LINUX_KERNEL_BINARY_ORIGIN' and
the file to be process is not 'vmlinux'.

Note that `ctf_close' must be called after processing all group's
members so it is executed from the destructor of `reader_context'.

The basic algorithm used to generate the Linux corpus is the
following:

   1. Looking for: vmlinux, *.ko objects, and vmlinux.ctfa files. The
   first files are used to extract the ELF symbols, and the last one
   contains the CTF type information for non-static variables and
   functions symbols.

   2. `process_ctf_archive' iterates on public symbols for vmlinux and
   its modules, using the name of the symbol, ctf reader search for CTF
   information in its dictionary, if the information was found it
   builds a `var_decl' or `function_decl' depending of `ctf_type_kind'
   result.

This algorithm is also applied to ELF files (exec, dyn, rel), so
instead of iterating on all ctf_types it just loops on the public
symbols.

	* abg-elf-reader-common.h: Include ctf-api.h file.
	(read_and_add_corpus_to_group_from_elf, set_read_context_corpus_group)
	(reset_read_context, dic_type_key): Declare new member functions.
	* include/abg-ir.cc (types_defined_same_linux_kernel_corpus_public): Use
	bitwise to know the corpus `origin'.
	* src/abg-ctf-reader.cc: Include map, algorithms header files.
	(read_context::type_map): Change from unordered_map to std::map storing
	ctf dictionary name as part of the key.
	(read_context::is_elf_exec): Add new member variable.
	(read_context::{cur_corpus_, cur_corpus_group_}): Likewise.
	(read_context::unknown_types_set): Likewise.
	(read_context::{current_corpus_group, main_corpus_from_current_group,
	has_corpus_group, current_corpus_is_main_corpus_from_current_group,
	should_reuse_type_from_corpus_group}): Add new member functions.
	(read_context::{add_unknown_type, lookup_unknown_type, initialize}):
	Likewise.
	(read_context::{add_type, lookup_type}): Add new `ctf_dict_t' type
	argument.
	(ctf_reader::{process_ctf_typedef, process_ctf_base_type,
	process_ctf_function_type, process_ctf_forward_type,
	process_ctf_struct_type, process_ctf_union_type, process_ctf_array_type,
	process_ctf_qualified_type, process_ctf_enum_type}): Add code to `reuse'
	types already registered in main corpus `should_reuse_type_from_corpus_group'.
	Use new `lookup_type' and `add_type' operations on `read_context::types_map'.
	Replace function calls to the new ctf interface. Add verifier to not build
	types duplicated by recursive calling chain.
	(ctf_reader::process_ctf_type): Add code to return immediately if the
	ctf type is unknown. Add unknown types to `unknown_types_set'.
	(ctf_reader::process_ctf_archive): Change comment.
	Add code to iterate over global symbols, searching by symbol name in the
	ctf dictionary using `ctf_lookup_{variable,by_symbol_name}' depending of
	the ELF file type and corpus type, creating a `{var,fuc}_decl' using the
	return type of `ctf_type_kind'.  Also close the ctf dict and call
	`canonicalize_all_types'.
	(slurp_elf_info): Set `is_elf_exec' depending of ELF type.  Also return
	success if corpus origin is Linux and symbol table was read.
	(ctf_reader::read_corpus): Add current corpus.  Set corpus origin to
	`LINUX_KERNEL_BINARY_ORIGIN' if `is_linux_kernel' returns true.  Verify
	the ctf reader status, now the ctf archive is 'opened' using
	`ctf_arc{open,bufopen}' depending if the corpus origin has
	`corpus::LINUX_KERNEL_BINARY_ORIGIN' bit set. Use
	`sort_{function,variables}' calls after extract ctf information.
	`ctf_close' is called from `read_context' destructor.
	(read:context::{set_read_context_corpus_group, reset_read_context,
	read_and_add_corpus_to_group_from_elf, dic_type_key): Add new member
	function implementation.
	* include/abg-tools-utils.h (build_corpus_group_from_kernel_dist_under):
	Add `origin' parameter with default `corpus::DWARF_ORIGIN'.
	* src/abg-tools-utils.cc: Use `abg-ctf-reader.h' file.
	(maybe_load_vmlinux_dwarf_corpus): Add new function.
	(maybe_load_vmlinux_ctf_corpus): Likewise.
	(build_corpus_group_from_kernel_dist_under): Update comments.
	Add new `origin' argument. Use `maybe_load_vmlinux_dwarf_corpus'
	or `maybe_load_vmlinux_ctf_corpus' according to `origin' value.
	* src/abg-corpus.h (corpus::origin): Update `origin' type
	values in enum.
	* src/abg-corpus-priv.h (corpus::priv): Replace `origin' type
	from `corpus::origin' to `uint32_t'.
	* src/abg-corpus.cc (corpus::{get,set}_origin): Replace data
	type from `corpus::origin' to `uint32_t'.
	* tools/abidw.cc (main): Use of --ctf argument to set format debug.
	* tests/test-read-ctf.cc: Add new tests to harness.
	* tests/data/test-read-ctf/test-PR27700.abi: New test expected
	  result.
	* tests/data/test-read-ctf/test-anonymous-fields.o.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-many-ctf.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-many.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-symbol-ctf.o.hash.abi: Likewise.
	* tests/data/test-read-common/test-PR26568-2.o: Adjust.
	* tests/data/test-read-ctf/test-PR26568-1.o.abi: Likewise.
	* tests/data/test-read-ctf/test-PR26568-2.o.abi: Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-A.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-B.c: Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-B.o: Likewise.
	* tests/data/test-read-ctf/test-ambiguous-struct-B.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-array-of-pointers.abi: Likewise.
	* tests/data/test-read-ctf/test-callback.abi: Likewise.
	* tests/data/test-read-ctf/test-callback2.abi: Likewise.
	* tests/data/test-read-ctf/test-conflicting-type-syms-a.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-conflicting-type-syms-b.o.hash.abi:
	Likewise.
	* tests/data/test-read-ctf/test-dynamic-array.o.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-ctf.o.abi: Likewise.
	* tests/data/test-read-ctf/test-enum-symbol.o.hash.abi: Likewise.
	* tests/data/test-read-ctf/test-enum.o.abi: Likewise.
	* tests/data/test-read-ctf/test-forward-type-decl.abi: Likewise.
	* tests/data/test-read-ctf/test-functions-declaration.abi: Likewise.
	* tests/data/test-read-ctf/test-list-struct.abi: Likewise.
	* tests/data/test-read-ctf/test0: Likewise.
	* tests/data/test-read-ctf/test0.abi: Likewise.
	* tests/data/test-read-ctf/test0.c: Likewise.
	* tests/data/test-read-ctf/test0.hash.abi: Likewise.
	* tests/data/test-read-ctf/test1.so.abi: Likewise.
	* tests/data/test-read-ctf/test1.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test2.so.abi: Likewise.
	* tests/data/test-read-ctf/test2.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test3.so.abi: Likewise.
	* tests/data/test-read-ctf/test3.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test4.so.abi: Likewise.
	* tests/data/test-read-ctf/test4.so.hash.abi: Likewise.
	* tests/data/test-read-ctf/test5.o.abi: Likewise.
	* tests/data/test-read-ctf/test7.o.abi: Likewise.
	* tests/data/test-read-ctf/test8.o.abi: Likewise.
	* tests/data/test-read-ctf/test9.o.abi: Likewise.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-13 09:11:37 +02:00
vsoch
707e47f4ce Add Logic to detect file type by extension
Fedabipkgdiff uses mimetypes to detect what file type it is looking
at. In some minimal versions of the OS, in particular container
images, the package that includes all the mimetypes may not be
installed. This allows fedabipkgdiff to fall back to using the
extension.

    * tools/fedabipkgdiff - add logic to detect file type by extension

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
Reviewed-by: Ben Woodard <woodard@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-12 12:10:15 +02:00
Ben Woodard
c7a71ba2d1 Add an option ignore SONAME differences in libraries
There are rare use cases where we do not want to compare the SONAME when
testing libraries for compatiblity or diffing libraries. This adds an
option to ignore the SONAME when doing the comparison. In these cases,
we will edit the application's DT_NEEDED to point to the other library.

This reuses the show_soname_change() function and slightly changes its
meaning to not only control if the sonames are printed but also if
they are compared. There didn't seem to be any other users of this
function and slight semantic change seemed harmless.

	* doc/manuals/abicompat.rst - added new option
	* doc/manuals/abidiff.rst - added new option to manpage
	* src/abg-comparison.cc (compute_diff): don't bother comparing the
	sonames if you aren't going to print them.
	* tools/abicompat.cc (options::ignore_soname): Add new data
	member.
	(parse_command_line): Support the new --ignore-soname command line
	option.
	(display_usage): Add a description string for the new
	--ignore-soname command line option.
	(create_diff_context): Set the diff_context::show_soname_change
	from the new options::ignore_soname data member.
	* tools/abidiff.cc (options::ignore_soname): Add new data member.
	(display_usage): Add a description string for the new
	--ignore-soname command line option.
	(parse_command_line): Support the new --ignore-soname command line
	option.
	(set_diff_context_from_opts): Set the
	diff_context::show_soname_change from the new
	options::ignore_soname.

Signed-off-by: Ben Woodard <woodard@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-12 11:58:18 +02:00
Giuliano Procida
c96463e1ad symtab: fix up 64-bit ARM address which may contain tags
64-bit ARM addresses normally have bits 47 to 63 as either all 0 or
all 1.  If tagging is used, bits 56 to 63 can vary, but the
interpretation of such values is as if the bits were all the same as
bit 55.

Such tagging is used for HWASAN and this affects the ELF symbol values
seen in shared libraries.

This commit changes the interpretation of 64-bit ARM symbol values by
unconditionally extending bit 55 into bits 56 to 63.

This fixes missing types for symbols in HWASAN-compiled libraries.

	* src/abg-elf-helpers.cc: (architecture_is_arm64): Add helper.
	* src/abg-elf-helpers.h: Likewise.
	* src/abg-symtab-reader.cc: (get_symbol_value): Adjust 64-bit
	ARM symbol values by extending bit 55 into bits 56 to 63.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-05-04 11:44:04 +02:00
Giuliano Procida
5106149c77 symtab: refactor ELF symbol value tweaks
A previous changes duplicated some logic for tweaking ELF symbol
values (and possibly updating some bookkeeping information).

This change refactors the code so the logic is in one place, in
symtab::get_symbol_value.

	* src/abg-symtab-reader.cc (symtab::load_): Replace address
	tweaking logic with a call to get_symbol_value.
	(symtab::add_alternative_address_lookups): Likewise.
	(symtab::get_symbol_value): New function containing address
	tweaking logic for PPC and ARM.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-05-04 11:34:46 +02:00
Guillermo E. Martinez
9054dbf9e2 ctf-reader: Fix multiple var-decl in anonymous struct/uninons
This patch avoids multiple inclusion of `var-decl' node for the same
field in anonymous struct/union declaration in the abixml, e.g:

  struct uprobe_task {
   union {
    struct {
     unsigned long vaddr;
    };

    struct {
     int dup_xol_work;
    };
   };
  };

Three `var-decl' nodes are written in abixml file, expected a single
one:
  <var-decl name='dup_xol_work' .../>

	* src/abg-ctf-reader.cc (process_ctf_sou_members): Remove
	CTF_MN_RECURSE flag.
	* tests/data/Makefile.am: Add new input test files.
	* tests/data/test-read-ctf/test-anonymous-fields.c: New
	test file.
	* tests/data/test-read-ctf/test-anonymous-fields.o: New
	expected test output.
	* tests/data/test-read-ctf/test-anonymous-fields.o.abi:
	Likewise.
	* tests/test-read-ctf.cc: Add new test.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-02 17:51:04 +02:00
Guillermo E. Martinez via Libabigail
fecdcac890 tools-utils: `entry_of_file_with_name' returns incorrect result
entry_of_file_with_name uses `string_ends_with' to test if the
filename given in the `fts_path' member of `FTSENT' matches the
`fname' argument.  This result is not correct when in the current
directory there are file with names: "./rmdir-xyx", "./dir-xyz" it
returns true for both files, this patch fixes this ambiguity by using
`basename' instead of `string_ends_with'.

	* src/abg-tools-utils.cc (entry_of_file_with_name): Replace
	call `string_ends_with' by `basename'.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-02 17:29:11 +02:00
Ben Woodard
f52c0ba416 Fix typo in abipkgdiff manpage
Add double dash to option name in man page. A minor typo.

        * doc/manuals/abipkgdiff.rst: add missing `--`

Signed-off-by: Ben Woodard <woodard@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-05-02 17:19:02 +02:00
Guillermo E. Martinez via Libabigail
6716aa042b ctf-reader: Add support to undefined forward declaration types
Undefined struct/union forward declaration types are not serialized in
abixml representation using `class-decl' node.

For instance, consider:

    struct key_type;
    typedef void (*key_restrict_link_func_t)(struct key_type *type);

Expected node:

  <class-decl name='key_type' ... is-declaration-only='yes'.../>

	* src/abg-ctf-reader.cc (process_ctf_forward_type): New
	function.
	(process_ctf_type): New CTF_K_FORWARD case.
	* tests/data/test-read-ctf/test-forward-undefine-type-decl.c:
	New testcase.
	* tests/data/test-read-ctf/test-forward-undefine-type-decl.abi:
	New expected result.
	* tests/data/test-read-ctf/test-forward-undefine-type-decl.o
	New test input.
	* tests/test-read-ctf.cc: Add new testcase to test harness.
	* tests/data/Makefile.am: Add new test input files to test harness.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-04-29 12:46:33 +02:00
Dodji Seketeli
9eb931c10d comparison: Avoid sorting diff nodes with wrong criteria
This should address PR28939, reported at
https://sourceware.org/bugzilla/show_bug.cgi?id=28939

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

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

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

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

	* src/abg-comparison.cc (diff::append_child_node): Do not sort
	children nodes here because they must have been sorted already.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt: Adjust.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt: Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt: Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm--libICE-1.0.9-2.el7.x86_64.rpm-report-0.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-03-10 10:57:53 +01:00
Dodji Seketeli
591a0f9e3e comparison: Factorize the code that inserts diff nodes to the graph
During the traversal of the graph of diff nodes, diff::traverse does
two things:

    1/ If the generic view of the diff node of is not yet connected to
    the diff graph, then connect it.  Note that the typed view of the
    diff node is always connected to the diff graph.

    2/ Visit the diff node using its generic view and visit its
    children nodes.

Looking at the part 1/, I realized that the code connecting the
generic view of the diff node to the diff graph was duplicated in
every single type of diff node.

This patch put that code into diff::finish_diff_type and makes all the
different kinds diff node use that (virtual) member function,
effectively factorizing that code.

	* include/abg-comparison.h ({distinct, var, pointer, reference,
	array, qualified_type, enum, class_or_union, class, union, base,
	scope, fn_parm, function_type, function_decl, type_decl,
	typedef}_diff::finish_diff_type): Remove these declarations.
	* src/abg-comparison.cc ({distinct, var, pointer, reference,
	array, qualified_type, enum, class_or_union, class, union, base,
	scope, fn_parm, function_type, function_decl, type_decl,
	typedef}_diff::finish_diff_type): Remove these definitions.
	(diff::finish_diff_type): Add the code to connect the children
	nodes to the current node, making the generic view of the diff
	node usable to walk the graph.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-03-07 18:12:10 +01:00
Dodji Seketeli
8fcab6d5c1 comparison: Describe the "generic view" of a diff node
To add a node to the diff graph, what is used is the "generic view"
(or generic API) of the diff node.

To understand the difference between the generic view and the typed
view of diff nodes, this patch adds comments to the diff node API.

	* include/abg-comparison.h (class diff): Add comments to this class.
	(diff::chain_into_hierarchy): Add comment to this method.
	* src/abg-comparison-priv.h (diff::priv): Add comment to this class.
	* src/abg-comparison.cc (diff::finish_diff_type): Add comment to
	this method.
	(diff::traverse): Add comment.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-03-07 18:11:59 +01:00
Dodji Seketeli
f07151ff9b Bug 28013 - Acknowledge variadic parameter type is not canonicalized
Variadic parameter types are one of the rare types that should not be
canonicalized, just like the void type.  These types are created by
the system (compiler/libabigail) and thus can be compared in O(1)
time.  So far, I forgot to prevent the canonicalization of variadic
parameter type everywhere, as should have been the case since the
recent introduction of the is_non_canonicalized_type function.  This
patch fixes that.

	* src/abg-ir.cc (is_non_canonicalized_type): Recognize variadic
	parameter types.
	* tests/data/test-diff-filter/test-PR28013-fn-variadic.c.{0,1}.abi: New test inputs.
	* tests/data/test-diff-filter/test-PR28013-fn-variadic.c.report.txt: Likewise.
	* tests/data/Makefile.am: Add the new test files to source distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the new tests to
	this harness.
	* 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/test0.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.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-filter/test-PR28013-fn-variadic.c.0.abi: Likewise.
	* tests/data/test-diff-filter/test-PR28013-fn-variadic.c.1.abi: Likewise.
	* tests/data/test-diff-filter/test-PR28013-fn-variadic.c.report.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/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test0.abi: Likewise.
	* tests/data/test-read-dwarf/test0.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/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Likewise.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-03-07 09:59:15 +01:00
Dodji Seketeli
c696400f21 dwarf-reader: Don't propagate canonical type upon aggregate redundancy
This comes from trying to fix
https://sourceware.org/bugzilla/show_bug.cgi?id=26646.

During DIE comparison for the purpose of DIE canonicalization, we need
to detect a loop due to a recurring aggregate comparison.  Thus, the
compare_dies function returns true in when it detects that it's
comparing two aggregate that are already being compared.  In that
situation of "detected aggregate redundancy", even though the
comparison seemingly succeeds, no canonical type propagation should
happen.

This patch prevents canonical type propagation when compare_dies
return true to signal aggregate redundancy detection.

This addresses https://sourceware.org/bugzilla/show_bug.cgi?id=26646#c21.

	* src/abg-dwarf-reader.cc (compare_dies): Do not propagate
	canonical type when aggregate redundancy is detected.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-03-03 12:44:36 +01:00
Dodji Seketeli
bfd5570403 Bug 26646 - unexpected declaration-only types (part 2)
This patch addresses the comment
https://sourceware.org/bugzilla/show_bug.cgi?id=26646#c15 of the
reported problem.

The core of the problem seems to be that when compare_dies compares
two DW_TAG_{structure,union}_type, it "gives up" when the comparison
stack contains more than 5 such DIEs being compared.  Giving up means
that it considers the two DIEs to be equivalent if they have the same
size and kind, basically.  This is to avoid infinite loops or too long
loops that we've seen with artificial DWARF input generated by
fuzzers.

This patch fixes that by better using the "aggregates_being_compared"
data structure that is meant to prevent looping infinitely over
aggregate DIEs that might be recursively defined.  That data structure
now contains the DWARF offset pairs of the DIEs being compared, rather
than their "string representation".  Lookups in that data structure
should now be faster and more precise.

The artificial limit of the comparison stack not having more than 5
DIEs is now lifted.

	* src/abg-dwarf-reader.cc (struct dwarf_offset_pair_hash)
	(dwarf_offset_pair_set_type): Define new type.
	(die_offset, has_offset_pair, insert_offset_pair)
	(erase_offset_pair): Define new static helper functions.
	(compare_dies): Use a set of DWARF offsets for the
	'aggregates_being_compared' data structure, rather than a set of
	string representation of the DIEs.  Always look at the size of the
	types being compared first so that we can get out quickly if they
	differ.  For DIEs of DW_TAG_{union,struct}_type kind, don't limit
	the depth of the stack of DIEs being compared to 5; so we don't
	consider two types as being equal just because the depth of the
	stack being compared is 5 and the two types have the same size and
	are equal.  Hopefully things don't take too long.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-03-02 17:24:36 +01:00
Dodji Seketeli
67d6b8e1c8 ir: Remove obsolete comment from enumerator equal operator
While looking at something else, I realized that some parts of the
comment of the equal operator of enumerator are obsolete.  I am
removing it.

	* src/abg-ir.cc (enum_type_decl::enumerator::operator==): Remove
	the obsolete parts from the comment.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-03-01 12:03:22 +01:00
Dodji Seketeli
4358470f07 reader: Fix a compilation warning
* src/abg-reader.cc (build_var_decl): Add braces to an 'if'
	statement.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-03-01 11:43:19 +01:00
Dodji Seketeli
1eb3dc84f7 abilint --show-type-use: Show results for global decls that have no symbols
In some abixml file, there can be global decls that don't have ELF
symbols.  We still want to see how those decls use the type that is
being used, as analyzed by abilint --show-type-use <type-id>.

	* include/abg-fwd.h (is_at_global_scope): Declare ...
	* src/abg-ir.cc (is_at_global_scope): ... new overload.
	* tools/abilint.cc (emit_artifact_use_trace): Emit the trace also
	when the decl is at global scope or has a linkage name.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-02-28 17:30:04 +01:00
Dodji Seketeli
1483f6cb49 abilint: add the --show-type-use option
"abilint --show-type-use <type-id> <abixml-file>" is a facility that
shows how a type defined in an abixml file is used.  That is, it emits
a textual representation of how the use a type is used up until the
function or global variable that constitutes an entry point in the API
corpus.  Here is an example of its use:

    test-read-write$ abilint --noout --show-type-use type-id-5 test17.xml
    Type ID 'type-id-5' is for type 'enum E'
    The usage graph for that type is:
    | -> enum E -> E S::m2 -> class S -> S* -> method void S::S()
    | -> enum E -> E S::m2 -> class S -> S* -> method void S::__base_ctor ()
    | -> enum E -> E S::m2 -> class S -> S* -> method void S::__comp_ctor ()
    | -> enum E -> E S::m2 -> class S -> S* -> method void S::S(S&)
    | -> enum E -> E S::m2 -> class S -> S* -> S& -> method void S::S(S&)
    | -> enum E -> E S::m2 -> class S -> S* -> S& -> S var
    | -> enum E -> E S::m2 -> class S -> S* -> S& -> E S::m2 -> class S -> S* -> method void S::S()
    | -> enum E -> E S::m2 -> class S -> S* -> S& -> E S::m2 -> class S -> S* -> method void S::__base_ctor ()
    | -> enum E -> E S::m2 -> class S -> S* -> S& -> E S::m2 -> class S -> S* -> method void S::__comp_ctor ()
    | -> enum E -> E S::m2 -> class S -> S* -> S& -> E S::m2 -> class S -> S* -> method void S::S(S&)
    | -> enum E -> E S::m2 -> class S -> S* -> S& -> E S::m2 -> class S -> S* -> S& -> method void S::S(S&)
    | -> enum E -> E S::m2 -> class S -> S* -> S& -> E S::m2 -> class S -> S* -> S& -> S var
    $

The screenshot above should be self explanatory.

This facility is useful to analyse type usage and find potential
issues in how libabigail represents some types.

To activate this feature, one needs to configure the package with the
configure option "--enable-show-type-use-in-abilint".

	* configure.ac: Define the --enable-show-type-use-in-abilint
	configure option.  It defines the WITH_SHOW_TYPE_USE_IN_ABILINT
	macro.
	* include/abg-reader.h (read_translation_unit): Add an overload
	that takes the read context.
	(get_types_from_type_id, get_artifact_used_by_relation_map):
	Declare new functions.
	* src/abg-reader.cc (get_types_from_type_id)
	(get_artifact_used_by_relation_map): Declare these functions as
	friend of the read_context type.
	(read_context::m_artifact_used_by_map):
	(read_context::key_type_decl): Replace the shared_ptr<type_base>
	type of the first parm by the equivalent type_base_sptr type.
	(read_context::{record_artifact_as_used_by,
	record_artifacts_as_used_in_fn_decl,
	record_artifacts_as_used_in_fn_type}): Add new methods guarded by
	the WITH_SHOW_TYPE_USE_IN_ABILINT macro.
	(get_types_from_type_id, get_artifact_used_by_relation_map): Define
	new functions guarded by the WITH_SHOW_TYPE_USE_IN_ABILINT macro.
	(read_translation_unit): Define new overload.
	(RECORD_ARTIFACT_AS_USED_BY, RECORD_ARTIFACTS_AS_USED_IN_FN_DECL)
	(RECORD_ARTIFACTS_AS_USED_IN_FN_TYPE): Define new macros.
	(build_function_decl, build_var_decl, build_qualified_type_decl)
	(build_pointer_type_def, build_reference_type_def)
	(build_function_type, build_array_type_def, build_enum_type_decl)
	(build_typedef_decl, build_class_decl, build_union_decl): Use the
	macros above to mark the relevant sub-types as used by the
	artifact being built.
	* tools/abilint.cc (struct artifact_use_relation_tree): Define new
	type, guarded by the WITH_SHOW_TYPE_USE_IN_ABILINT macro.
	(fill_artifact_use_tree, build_type_use_tree, emit_trace)
	(emit_artifact_use_trace, emit_artifact_use_trace)
	(show_how_type_is_used): Define static functions guarded by the
	WITH_SHOW_TYPE_USE_IN_ABILINT macro.
	(display_usage): Add doc string for the --show-type-use option,
	guarded by the WITH_SHOW_TYPE_USE_IN_ABILINT macro.
	(parse_command_line): Parse the --show-type-use option, guarded by
	the WITH_SHOW_TYPE_USE_IN_ABILINT macro.
	(main): Slight re-organisation to make the abixml file reading use
	a read_context.  That read context is then used to analyze how a
	given type is used whenever the --show-type-use option is used.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-02-28 10:24:46 +01:00
Dodji Seketeli
29241edd13 configure: Remove use of obsolete AC_CONFIG_HEADER
* configure.ac: Replace the use of the obsolete AC_CONFIG_HEADER
	by AC_CONFIG_HEADERS.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-02-28 10:24:26 +01:00
Randy MacLeod
4aa7f38334 Improve some grammar
Fix typos and try to improve some grammar in the files
in the top level directory.

        * COMPILING: Improve grammar
        * CONTRIBUTING: Improve grammar
        * README: Improve grammar
        * VISIBILITY: Improve grammar

Signed-off-by: Randy MacLeod <Randy.MacLeod@windriver.com>
2022-02-25 11:24:20 +01:00
Giuliano Procida
f723989845 XML writer: do not create extra temporary referenced type shared_ptr
In the loop of write_referenced_types temporary shared_ptr objects are
created. In the case of a declaration, two shared_ptrs are created. It
is possible to code this so only one object is created.

This is a small optimisation with no change to tests or behaviour.

	* src/abg-writer.cc (write_referenced_types): Create temporary
	shared_ptr objects within each conditional branch instead of
	outside the conditionals and within one of the branches.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-02-24 18:33:49 +01:00
Giuliano Procida
628dbfebd6 XML writer: improve slightly emission of top-level declarations
In the loop that emits declarations, the iterator already points to a
decl_base_sptr, there is no need to do another dynamic_cast. It is
also possible to simplify the loop and its conditionals.

There is no change to tests or behaviour.

	* src/abg-writer.cc (decl_is_emitted): Make decl_base_sptr
	argument a const reference.
	(write_translation_unit): Eliminate a typedef and just use a
	range-for loop without the extra dynamic cast for the non-type
	case. Use else instead of continue to make it clear there are
	only two possibilities.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-02-24 18:26:36 +01:00
Giuliano Procida
e21ff7aead XML writer: drop write_elf_symbols_table variable emitted_syms
This was introduced in commit e2d45017 and was unused then.

	* src/abg-writer.cc (write_elf_symbols_table): Drop unused
	local variable emitted_syms.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-02-24 18:16:21 +01:00
Giuliano Procida
876415a225 XML writer: remove type_hasher and remaining comment
The type_hasher functor is no longer used.

	* src/abg-writer.cc (type_hasher): Remove this unused functor.
	Remove a following comment referencing it.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-02-24 15:14:24 +01:00
Dodji Seketeli
f86ff3f7a7 Bug 26646 - unexpected declaration-only types
In a version of the kernel binary referred to in this problem report,
the parameter 'skb' of the udp4_hwcsum function, which is of type
"pointer to struct sk_buff", indirectly refers to a pointer to a
declaration-only struct ip_mc_list.

In another version of that kernel binary, the same parameter skb of
the udp4_hwcsum function is still of type "pointer to struct sk_buff",
but in that case, the sk_buff indirectly refers to a pointer to a
fully defined struct ip_mc_list.

The first kernel only contains a decl-only struct ip_mc_list whereas
the second one contains a fully defined struct ip_mc_list.

This problem comes from the fact that in add_or_update_class_type, we
"reuse" the "struct sk_buff" that we've already seen in the same
binary, if any.  Depending on the order in which types are defined in
the debug information, if the DIE for struct sk_buff that refers to a
decl-only struct ip_mc_list has already been "seen" by the
DWARF-reader, then add_or_update_class_type re-uses the IR of that DIE
that's been constructed already; otherwise, the IR for the struct
sk_buff represented by the current DIE is constructed.

This patch fixes the problem by always constructing an IR for the
DIE that is being seen, in add_or_update_class_type.

	* src/abg-dwarf-reader.cc (add_or_update_class_type): Do not reuse
	the IR for a DIE with the same textual representation as the one
	we are seeing now.
	* tests/data/test-annotate/test21-pr19092.so.abi: Adjust.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-02-08 11:11:51 +01:00
Dodji Seketeli
07f494aa46 symtab-reader: Remove an over-agressive assertion
In symtab::load, the symtab reader walks the symbol table and records
each relation "symbol <-> address".
So, the relation "foo <-> address-of-foo" is going to be recorded.
The relation "foo.cfi <-> address-of-foo.cfi" is going to be recorded
as well.

But then, because the symbol foo.cfi has a special meaning, in the
realm of "control flow integrity", the relation "foo.cfi <->
address-of-foo.cfi" (as well as all the *.cfi <-> address-of*.cfi
relations) is going to be recorded (again but) in a particular way by
calling symtab::add_alternative_address_lookups.

The problem is that in, symtab::add_alternative_address_lookups there
is an assert that (wrongly) assumes that the relation foo.cfi <->
address-of-foo.cfi is being seen for the first time.  This is wrong
because the loop in symtab::load that records all the "symbol <->
address" relations has seen and recorded this foo.cfi <->
address-of-foo.cfi relation once already.

This patch removes that assert so that the kernel referred to in the bug
report of PR26646, as mentioned in
https://sourceware.org/bugzilla/show_bug.cgi?id=26646#c5, can be
processed by abidw without crashing.

	* src/abg-symtab-reader.cc
	(symtab::add_alternative_address_lookups): Remove over-aggressive
	assert.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Reviewed-by: Giuliano Procida <gprocida@google.com>
2022-02-07 17:47:32 +01:00
David Seifert
1198798985 Find fts-standalone on musl
When using the musl C library fts is optional.  So we need to detect
its presence by looking at the fts-standalone pkgconfig module.

This patch does that.

This comes from Gentoo bug https://bugs.gentoo.org/831571

	* configure.ac: Invoke AC_CANONICAL_HOST to compute the host_cpu,
	host_vendor, host_os parts of the 'host" variable.  Then if the
	host_os ends up with "musl" then, check for the fts-standalone
	pkgconfig module and record the fts library into
	FTS_{LIBS,CFLAGS}.
	* src/Makefile.am: Link to $FTS_LIBS and use $FTS_CFLAGS for
	compilation.
	* tools/Makefile.am: Likewise.
	* tools/abisym.cc: Include libgen.h
	* tools/kmidiff.cc: Remove useless fts.h header file.

Signed-off-by: David Seifert <soap@gentoo.org>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-02-07 16:26:30 +01:00
Dodji Seketeli
6357941e61 symtab-reader: Fix typo in comment
* src/abg-symtab-reader.cc
	(symtab::update_function_entry_address_symbol_map): Fix typo in
	comment.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-02-07 11:42:44 +01:00
Dodji Seketeli
3866f163f9 writer: small compilation error fix
* abg-writer.cc (write_type_record): Fix const-ness in argument
	passing.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-01-20 15:32:56 +01:00
Matthias Maennich
194a3029bd abidiff: improve whitespace generation in symbol diff report
maybe_report_diff_for_symbol() has a few issues:

1. The responsibility for newline emission is somewhat unclear and
   indeed it would emit spurious blank lines before most of the
   sub-diffs it reports.

2. Different sub-diff text and terminal commas are emitted according to
   whether or not there had been a previous sub-diff - making the output
   harder to grep and post-process.

3. The function also returns a bool but that return value is never used.

Hence, change the function to return void, the function stanzas to
always emit newline-terminated lines and ensure the wording and
punctuation of each sub-diff do not vary. This also tweaks (shortens)
the wording used for CRC diffs.

	* src/abg-reporter-priv.cc (maybe_report_diff_for_symbol):
	Make return void. Simplify and fix new-line emission. Remove
	comma emission. Tweak CRC wording.
	* src/abg-reporter-priv.h (maybe_report_diff_for_symbol):
	Return void.
	* tests/data/test-abidiff-exit/test-crc-report.txt: Shorten CRC
	wording.
	* tests/data/test-abidiff/test-crc-report.txt: Likewise.
	* tests/data/test-diff-filter/test-PR27569-report-0.txt:
	Likewise.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
2022-01-19 14:48:03 +01:00
George Rawlinson
eb3e549794 Bug 28663 - generate man page for kmidiff
This patch is based on a patch submitted to this bug report by George
Rawlinson <grawlinson@archlinux.org>.

It generates a man page for the kmidiff tool.

	* doc/manuals/conf.py: Update copyright year.  Generate man page
	for the kmidiff tool.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-01-19 12:29:12 +01:00
Matthias Maennich
e5bed8512f XML writer: resolve declaration-only enum definitions
Let the writer look through declaration-only enums for definitions.

This matches what get_preferred_type, write_class_decl and
write_union_decl do. No current test cases are affected.

	* src/abg-writer.cc (write_enum_type_decl): Look through
	declaration-only types the same as for structs and unions.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
2022-01-19 11:34:55 +01:00
Matthias Maennich
16e3d3a6f3 XML writer: map type ids by bare pointer
This is a performance and safety improvement made possible by previous
changes which ensure that the same pointers are used for insertion and
look-up.

This change affects two test cases. In more detail:

The test case test-read-dwarf/PR22122-libftdc.so.abi has many
duplicate type-id-60 which appear to all be types defined with a DWARF
DW_AT_signature attribute. These are made into separate types by this
change, but remain incomplete.

The test case test-read-dwarf/PR25007-sdhci.ko.abi has duplicate
declarations and these get split into duplicate declarations with new
type ids following this change. The test suite runs with an implicit
--no-linux-kernel-mode so the duplicates are treated separately. They
presumably had the same type ids before this change due to deep
equality considering them equal.

	* src/abg-writer.cc (type_ptr_map): use default equality on
	type_base pointer.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Refresh
	test case, as described above.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
2022-01-18 18:56:11 +01:00
Matthias Maennich
4565679f3d XML writer: track emitted types by bare pointer
This is a performance and safety improvement made possible by the
previous changes which ensure that the same pointers are inserted and
looked up.

This essentially removes the now unnecessary deep comparison.

	* src/abg-writer.cc (type_ptr_set_type): Change typedef
	container type to use default equality and hashing for pointer
	keys.
	(fn_type_ptr_set_type): Likewise.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-01-18 18:13:38 +01:00
Giuliano Procida
eab1463fea abidiff: include ABI XML versions when reporting a mismatch cont.
This fixes a copy/paste error in function documentation.

	* tools/abidiff.cc
	(emit_incompatible_format_version_error_message): Fix
	parameter documentation.

Fixes: b251bc611e ("abidiff: include ABI XML versions when reporting a mismatch")
Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-01-18 17:59:04 +01:00
Giuliano Procida
b251bc611e abidiff: include ABI XML versions when reporting a mismatch
In the rare event of an XML version mismatch it would be helpful to
have the versions in the error message, particularly if abidiff is
being run from automation.

	* tools/abidiff.cc
	(emit_incompatible_format_version_error_message): Add version1
	and version2 arguments. Add versions to error message.
	(main): Pass emit_incompatible_format_version_error_message
	mismatching versions.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-01-18 17:10:03 +01:00
Mark Wielaard
e825cef6e0 DWARF reader: use size_t for DWARF expression length cont.
A recent change broke 32-bit builds due to an implicit assumption that
size_t == uint64_t. Note that size_t is part of the elfutils
dwarf_getlocation* functions' types.

The previous fix omitted some instances of uint64_t. This commit
updates further functions to consistently use size_t for DWARF
expression lengths and indexes.

	* src/abg-dwarf-reader.cc (eval_last_constant_dwarf_sub_expr):
	Change expr_len argument type to size_t.
	(op_pushes_constant_value): Update ops_len and index argument
	types to size_t. Update next_index argument type to size_t&.
	(op_pushes_non_constant_value): Likewise.
	(op_is_arith_logic): Update expr_len and index argument types
	to size_t. Update next_index argument type to size_t&.
	(op_is_control_flow): Likewise.

Fixes: 16207c4af7 ("Bug 28191 - Interpret DWARF 5 addrx locations")
Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-01-18 16:58:18 +01:00
Giuliano Procida
6e0d3f7278 DWARF reader: use size_t for DWARF expression length
A recent change broke 32-bit builds due to an implicit assumption that
size_t == uint64_t. This appears in the elfutils dwarf_getlocation*
functions' types.

This commit updates callers and other functions to use size_t
consistently for such expression lengths and indexes.

	* src/abg-dwarf-reader.cc (die_location_expr): Change expr_len
	argument type to size_t*.
	(op_manipulates_stack): Change expr_len and index argument
	types to size_t; change next_index argument type to size_t&.
	(eval_last_constant_dwarf_sub_expr): Change expr_len argument
	and local variables index and next_index types to size_t.
	(die_member_offset): Change local variable expr_len type to
	size_t.
	(die_location_address): Likewise.
	(die_virtual_function_index): Likewise.

Fixes: 16207c4af7 ("Bug 28191 - Interpret DWARF 5 addrx locations")
Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-01-18 10:15:53 +01:00
Giuliano Procida
4ab1e456c0 symtab reader: fix up alternative addresses
CFI symbols need special interpretation and this work is performed by
the add_alternative_address_lookups method.

Some symbol addresses need to be "tweaked" to be correctly interpreted
and this must also happen in add_alternative_address_lookups.

In particular, this commit fixes ARM32 CFI symbol interpretation.

	* src/abg-symtab-reader.cc
	(symtab::add_alternative_address_lookups): Tweak function
	addresses in the same manner as done in symtab::load_.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-01-17 17:06:47 +01:00
David Cantrell
069ead6b55 Include <libgen.h> in tools/abisym.cc for basename(3)
Support building on non-glibc systems, such as musl, by including
libgen.h for basename(3).

Signed-off-by: David Cantrell <dcantrell@redhat.com>
2022-01-17 14:32:33 +01:00
Giuliano Procida
16207c4af7 Bug 28191 - Interpret DWARF 5 addrx locations
This change uses libdw facilities to interpret location expressions
instead of using libabigail's own mini-interpreter. With the fix for
elfutils https://sourceware.org/bugzilla/show_bug.cgi?id=28220 in
elfutils-0.186, abidw will correctly interpret Clang DWARF 5 symbol
addresses. Without that fix many declarations will not be linked to
their corresponding symbols due to the incorrect interpretation of
location attribute data.

	* src/abg-dwarf-reader.cc (die_location_address): Use
	dwarf_attr_integrate, dwarf_getlocation and
	dwarf_getlocation_attr to decode addreses, instead of
	die_location_expr and eval_last_constant_dwarf_sub_expr.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Refresh test reference output; two more symbols have types.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2022-01-17 13:58:08 +01:00
Dodji Seketeli
8569491741 Bug 28319 - re-fix of rhbz1951526 - SELF CHECK FAILED for 'gimp-2.10'
This commit re-visit the commit below:

    commit 1cfbff1b30
    Author: Dodji Seketeli <dodji@redhat.com>
    Date:   Mon Jun 7 16:07:50 2021 +0200

	rhbz1951526 - SELF CHECK FAILED for 'gimp-2.10'

	This is a fix for bug https://bugzilla.redhat.com/show_bug.cgi?id=1951526.

Basically, this commits makes is so that two enums below are
considered equal by libabigail:

     enum foo // This is foo #1
     {
       e0 = 0;
       e1 = 1;
       e2 = 2;
     };

     enum foo  // This is foo #2
     {
       e0 = 0;
       e1 = 1;
       e2 = 2;
       e_added = 1; // This enumerator is considered redundant
       	       	    // with the enumerator e1 because their values
		    // are the same.
     };

With this patch, foo #1 and foo #2 are considered equal, just like in
the original commit 1cfbff1b.  In the original commit however, this
was achieved by comparing the enums without considering their
enumerator names.  This was named "binary-only enum comparison".  In
reality, that approach was too big of a hammer and was causing the
issues raised in the bug.  Namely, type canonicalization would
conflate anonymous enums that were unrelated (precisely because their
enumerator names were different), leading to spurious type change
reports when comparing abixml files pre-dating commit 1cfbff1b with
posterior abixml files.

If I refer to the example above with foo #1 and #2, this patch detects
that the value of the enumerator 'e_added' is redundant with the value
of the enumerator e1.  As such, the two foo #1 and #2 are considered
equal.  Enumerator names are now fully taken into account.

With this precise approach, it now seems we can do away with the
careful dance of using "binary-only enum comparison" at some precise
times of the libabigail pipeline.  Now, we can just use the new enum
comparison scheme all the time.  Leading to less (complicated) code
and a hopefully accurate representation.

	* include/abg-ir.h (environment::use_enum_binary_only_equality):
	Remove.
	* src/abg-comparison.cc (compute_diff): In the overload for
	enum_type_decl, stop using binary-only-equality for enums.
	* src/abg-dwarf-reader.cc
	(read_context::compare_before_canonicalisation): Likewise.
	* src/abg-ir.cc (environment::use_enum_binary_only_equality):
	Remove.
	(enumerators_values_are_equal)
	(is_enumerator_value_present_in_enum)
	(is_enumerator_value_redundant): Define new static functions.
	(equals): In the overload for enum_type_decl, use the new
	is_enumerator_value_redundant to detect if two enums are equal
	modulo a redundant enumerator value.  In that case, consider they
	are equal.
	* tests/data/test-abidiff/test-enum0-report.txt: Adjust.
	* tests/data/test-annotate/test-anonymous-members-0.o.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-diff-dwarf/PR25058-liblttng-ctl-report-1.txt: 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/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-01-14 10:45:29 +01:00
Thomas Schwinge
71633a7c0c Handle several variants of Python 'imp', 'importlib' modules
Fix-up for recent commit f0582fdbf1
"Replace use of deprecated Python 'imp' module with 'importlib'", and
commit cc1f38ffed
"Replace Python 'import importlib' with 'import importlib.machinery'",
because compatibility...

	* tests/mockfedabipkgdiff.in: Handle several variants of Python
	'imp', 'importlib' modules.

Signed-off-by: Thomas Schwinge <thomas@codesourcery.com>
Tested-by: Mark Wielaard <mark@klomp.org> (CentOS 7)
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-01-06 15:44:29 +01:00
Dodji Seketeli
10fda2aa65 suppression: Fix compilation warning on el7
* src/abg-suppression.cc (type_suppression::suppresses_diff):
	Remove the unused variable second_type_decl.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2022-01-03 15:17:13 +01:00