Commit Graph

528 Commits

Author SHA1 Message Date
Dodji Seketeli
01e5bfc4a4 Bug 25007 - Don't use section-relative symbol values on ET_REL binaries
In relocatable files, two symbols listed in the .symtab section can
have the same value and yet be different.  That is because those
symbols can be *defined* in different sections.  And the value of
those symbols represent addresses (offsets) within their own
respective sections (a.k.a section-relative addresses).

In the same time, symbol address as referred-to in the DWARF
information are *not* section-relative, rather, they are relative to
the beginning of the whole binary.

Until now, the DWARF-referred-to symbol addresses were translated into
section-relative addresses, so that they could be compared to the
other section-relative addresses we were getting from listing the
symbols and their values from the .symtab section.  The problem with
that approach is that, during the translation from binary-relative to
section-relative addresses we were wrongly assuming that all symbols
referenced from the DWARF were defined in the .text section.  This is
wrong especially for ET_REL files because they could be defined in
sections named .foo.text or .bar.text, for instance.

This leads to issues where we wrongly consider that two symbols having the
same value are the same.  Because we wrongly assume that they are all
defined in the same .text section.

This patch fixes this problem by translating the section-relative
addresses we see in .symtab into binary-relative addresses by adding
the address of the section to the section-relative address.  Those
binary-addresses can thus safely be compared to the binary-relative
addresses we see in the DWARF.  And also, when two symbols have the
same binary-relative address, we can now safely assume that they are
the same -- they are aliases, basically.

	* src/abg-dwarf-reader.cc
	(read_context::{lookup_native_elf_symbol_from_index,
	maybe_adjust_et_rel_sym_addr_to_abs_addr}): Define new member
	functions.
	(read_context::lookup_elf_symbol_from_index): Add a new overload.
	Write the old overloads in terms of the new one.
	(read_context::{load_symbol_maps_from_symtab_section,
	populate_symbol_map_from_ksymtab_reloc}): Use the new
	maybe_adjust_et_rel_sym_addr_to_abs_addr function to translate the
	symbol value/address into a binary-relative address before adding
	it to the addr->sym maps.
	(read_context::maybe_adjust_{fn, var}_sym_address): Do not adjust
	DWARF-referred-to addresses of ET_REL symbols anymore.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko: New binary test input.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: ABI
	representation of the above.
	* tests/test-read-dwarf.cc: Add the new test input to the harness.
	* tests/data/test-diff-dwarf/test28-vtable-changes-report-0.txt: Adjust.
	* tests/data/test-diff-filter/test20-inline-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test20-inline-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test41-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test9-report.txt: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-09-20 14:13:12 +02:00
Dodji Seketeli
bc2d2ce660 Serialize canonical types to avoid testing if types have been emitted
When emitting abixml, profiling shows that we spend a great deal of
time testing if a given type has been emitted already, to avoid
emitting a given type more than once.  This makes the serialization
phase take more time than the binary analysis phase!

This patch leverages the fact that we already have the set of
canonical types in the system.  While emitting that set entirely, we
don't need to test if a type has been emitted already because we know
by definition that every type is present just once in that set, more
or less.  OK, because there are also types that don't have canonical
types (for instance, declaration-only class/structs), we'll still have
to check of those types have already been emitted, but this is a very
small set to handle.

The patch thus organizes the canonical types per scope, so that when
emitting a scope and the canonical types within it, the type is
emitted in its correct namespace.

Then, when emitting a translation unit and each namespaces in it, the
patch emits the canonical types of those namespaces.

The patch arranges for some ancillary things that are needed to make
the whole picture be coherent enough for things to keep working.

Testing shows that we gained ~ 30% of performance by doing this, while
analysing the whole linux kernel 5.1 version.  We went from ~ 3m30s
minutes to less than 2m30s.

With this patch, the serialization phase now takes less time than the
analysis time.

	* include/abg-fwd.h (is_decl_slow)
	(peel_pointer_or_reference_type): Declare new functions.
	* include/abg-ir.h (struct canonical_type_hash): Define new type.
	(type_base_ptr_set_type, type_base_ptrs_type)
	(type_base_sptrs_type, canonical_type_sptr_set_type): Define new
	typedefs.
	(environment::get_canonical_types_map): Declare new member
	function.
	(scope_decl::{get_canonical_types, get_sorted_canonical_types}):
	Declare new member functions.
	* src/abg-ir.cc (is_ptr_ref_or_qual_type)
	(peel_pointer_or_reference_type, is_decl_slow): Define new
	functions.
	(environment::{get_canonical_types_map}): Define new member
	functions.
	(canonical_type_hash::operator()): Likewise.
	(scope_decl::{get_canonical_types, get_sorted_canonical_types}):
	Likewise.
	(struct type_topo_comp): Define new comparison functor type.
	(environment::{sorted_canonical_types_}): Define new data member.
	(scope_decl::priv::{canonical_types_, sorted_canonical_types_}):
	Likewise.
	(scope_decl::is_empty): Take the presence of canonical types into
	account when determining if a scope is empty or not.
	(is_decl): Make this work for cases where the artifact at hand is
	a type which has a declaration, as opposed to being a pure
	declaration like a variable or a function.
	(canonicalize): Add the canonical type the list of canonical types
	of its scope.
	* src/abg-dwarf-reader.cc (read_context::die_is_in_cplus_plus):
	Define new member function.
	* src/abg-writer.cc (write_type, write_canonical_types_of_scope):
	Define new static functions.
	(fn_type_ptr_set_type): Define new typedef.
	(write_context::{m_referenced_fn_types_set,
	m_referenced_non_canonical_types_set}): Add new data members.
	(write_context::m_referenced_types_set): Renamed
	m_referenced_types_map into this.
	(write_context::get_referenced_types): Adjust.
	(write_context::get_referenced_{function_types,
	non_canonical_types}):
	(write_context::record_type_as_referenced): Adjust to add the
	referenced type in the proper set which would be one of the three
	following: write_context::{get_referenced_types,
	get_referenced_function_types,
	get_referenced_non_canonical_types}.
	(write_context::{type_is_referenced, clear_referenced}): Adjust.
	(write_translation_unit): Use the new
	write_canonical_types_of_scope.  Also emit declaration-only
	classes that have member types.  Do not test if a given type of a
	given scope has been emitted, in general, as this was super slow
	given the number of types.  Emit referenced function types (as
	these don't belong to any scope).  Rather than using the expensive
	"is_function_type" on *all* the referenced types, just walk the
	set write_context::get_referenced_function_types.  Likewise,
	rather than using type_base::get_naked_canonical_type on
	*all* the referenced types, just walk the set
	write_context::get_referenced_non_canonical_types
	(write_class): Use write_canonical_types_of_scope here.
	* tools/abilint.cc (main): Support linting corpus group abixml
	files.
	* 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/test-anonymous-members-0.o.abi: Likewise.
	* tests/data/test-annotate/test0.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-annotate/test2.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-annotate/test4.so.abi: Likewise.
	* tests/data/test-annotate/test6.so.abi: Likewise.
	* tests/data/test-annotate/test7.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi: Likewise.
	* tests/data/test-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/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/test0.abi: Likewise.
	* tests/data/test-read-dwarf/test1.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/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/test6.so.abi: Likewise.
	* tests/data/test-read-dwarf/test7.so.abi: Likewise.
	* tests/data/test-read-dwarf/test8-qualified-this-pointer.so.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.
	* tests/data/test-read-write/test10.xml: Likewise.
	* tests/data/test-read-write/test14.xml: Likewise.
	* tests/data/test-read-write/test15.xml: Likewise.
	* tests/data/test-read-write/test17.xml: Likewise.
	* tests/data/test-read-write/test18.xml: Likewise.
	* tests/data/test-read-write/test19.xml: Likewise.
	* tests/data/test-read-write/test2.xml: Likewise.
	* tests/data/test-read-write/test20.xml: Likewise.
	* tests/data/test-read-write/test21.xml: Likewise.
	* tests/data/test-read-write/test22.xml: Likewise.
	* tests/data/test-read-write/test23.xml: Likewise.
	* tests/data/test-read-write/test24.xml: Likewise.
	* tests/data/test-read-write/test25.xml: Likewise.
	* tests/data/test-read-write/test26.xml: Likewise.
	* tests/data/test-read-write/test27.xml: Likewise.
	* tests/data/test-read-write/test28-without-std-fns-ref.xml: Likewise.
	* tests/data/test-read-write/test28-without-std-vars-ref.xml: Likewise.
	* tests/data/test-read-write/test3.xml: Likewise.
	* tests/data/test-read-write/test6.xml: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-09-17 17:52:26 +02:00
Matthias Maennich
d7ae619ff3 Ensure a consistent C++ standard use
On older compilers (such as g++ 4.8), the default C++ standard is set to
gnu++98. When compiling libabigail with --enable-cxx11=yes, src/ and
tests/ where compiled with the correct flag, while tools/ was compiled
without specifying a standard. With a compiler falling back to gnu++98
that leads to unresolved references when linking the tools against the
libabigail library. Fix that by consistently using the std= flag across
the code base.

	* configure.ac: add -std=c++11 flag to CXXFLAGS when compiling
	for C++11
	* src/Makefile.am: drop now obsolete setting of the -std flag
	* tests/Makefile.am: likewise

Reported-by: Chun-Hung Wu <Chun-hung.Wu@mediatek.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-07-22 11:18:13 +02:00
Dodji Seketeli
f2437aabad Bug 24787 - Filter out enum changes into compatible integer types
Libabigail's filtering engine fails to recognize an enum changing into
a compatible integer (or vice versa) as a harmless change.

This patch fixes that.

	* include/abg-comparison.h (peel_typedef_or_qualified_type_diff):
	Declare new function.
	(peel_pointer_or_qualified_type_diff): Rename
	peel_pointer_or_qualified_type into this.
	* include/abg-fwd.h (is_enum_type): Declare a new overload for
	type_or_decl_base*.
	* src/abg-comp-filter.cc (has_harmless_enum_to_int_change): Define
	new static function.
	* src/abg-comparison.cc (categorize_harmless_diff_node): Use the
	new has_harmless_enum_to_int_change here.
	(peel_pointer_or_qualified_type_diff): Renamed
	peel_pointer_or_qualified_type into this.
	(is_diff_of_basic_type): Adjust.
	(peel_typedef_or_qualified_type_diff): Define new function.
	* test-diff-filter/PR24787-lib{one, two}.so: New test input
	binaries.
	* test-diff-filter/PR24787-{one, two}.c: Source files of the test
	input binaries above.
	* test-diff-filter/PR24787-report-0.txt: Test output reference.
	* tests/data/Makefile.am: Add the new testing material to source
	distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the new test to
	the test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-07-19 18:22:12 +02:00
Dodji Seketeli
400ac7a412 Implement fast comparison of Linux Kernel types when applicable
During type canonicalization there are observations that can speed-up
type comparison significantly without impacting correctness too much.

Typically, when two types are of the same name and kind, are found in
the same corpus and are defined in the same translation unit, they
ought to be the same type, even in C.  So there is no need in this
case to actually perform the structural comparison of the two types
which does have a quadratic performance at best.

Using this optimization made the loading of the
drivers/gpu/drm/i915/i915.ko module go from a quasi inifite time (many
hours on my system) to less than two minutes.  I am confining this
optimization to the Linux kernel case only for now, but I believe it
could benefit all C programs.  I am waiting for more testing before
applying it more broadly.

Also, while looking at this, I noticed that when loading several
corpora into a given corpus group (i.e, loading several linux kernel
binaries to represent a single conceptual kernel), we sometimes fail
to recognize that a type defined in a header file that is included in
several corpora is actually the same type, and should be re-used,
rather than being re-defined in each corpus.  This later adds stress
(time and space) on the system as we need to canonicalize and
de-duplicate these type later on.

This is because the "per-corpus" type maps that we use to lookup a
type by name and location when we see it (so that we know it's defined
in a different corpus of our current group) should really be
per-corpus-group type maps!  That is a type can be defined in the
corpus representing a .ko binary, and that type would be seen again in
another .ko binary later.  Until now, we were wrongly considering that
types were to be first defined in the corpus of the vmlinux binary,
and then could be re-used later.

I have thus fixed the code so that whenever we add a type to its
scope, the relevant per-corpus type maps are updated, as well as the
per-corpus-group ones, so that we can later lookup types in those
per-corpus-group type maps to know if a type is already defined in any
corpus of the group.

	* include/abg-corpus.h (corpus::origin): Add a new
	LINUX_KERNEL_BINARY_ORIGIN enumerator.
	(corpus::{s,g}et_group): Declare new member
	functions.
	(class corpus): Make the corpus_group class friend of this one.
	(corpus_group::get_main_corpus): Declare new member function.
	* src/abg-corpus-priv.h (corpus::priv::group): Define new data
	member.
	(corpus::priv::priv): Initialize the new corpus::priv::group data
	member.
	* src/abg-corpus.cc (corpus::{g,s}et_group): Define new member
	functions.
	(corpus_group::get_main_corpus): Likewise.
	(corpus_group::add_corpus): Use the new corpus::set_group() here
	to to make the corpus be aware of the group it belongs to.
	* src/abg-dwarf-reader.cc (read_debug_info_into_corpus): Set the
	current corpus origin to the corpus::LINUX_KERNEL_BINARY_ORIGIN if
	we are looking at a Linux Kernel binary.
	(read_context::main_corpus_from_current_group): Use the
	corpus_group::get_main_corpus method.
	(should_reuse_type_from_corpus_group): Return the corpus group,
	rather than the main corpus.
	(read_debug_info_into_corpus): Add the current corpus to the
	current corpus group before the debug info reading is done.  That
	way, the corpus group will be accessible from the current corpus
	during the construction of the internal representation.
	(read_and_add_corpus_to_group_from_elf): Add the corpus to the
	group only if it wasn't added to it before.
	* include/abg-ir.h (operator{==,!=}): Declare new deep equality
	and inequality operators for class_or_union_sptr and
	union_decl_sptr.
	* src/abg-ir.cc (types_defined_same_linux_kernel_corpus_public):
	Define a new static function.
	(type_base::get_canonical_type_for): Use the new
	types_defined_same_linux_kernel_corpus_public here to speed up
	type comparison.
	(equals): In the overload of class_or_union, use the new
	types_defined_same_linux_kernel_corpus_public as well, to speed up
	type comparison.
	(operator{==,!=}): Define new deep equality and inequality
	operators for class_or_union_sptr and union_decl_sptr.
	(maybe_update_types_lookup_map): In the overload function for
	type_decl_sptr, class_decl_sptr, union_decl_sptr,
	enum_type_decl_sptr, typedef_decl_sptr, qualified_type_def_sptr,
	reference_type_def_sptr, array_type_def_sptr,
	array_type_def::subrange_sptr, and function_type_sptr, update the
	type lookup maps of the containing corpus group as well, not just
	the ones of the current corpus.
	* src/abg-reader.cc (build_enum_type_decl): Forgot to set the
	"is-anonymous" flag.  Oops, fix this.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Adjust.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Adjust.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-07-17 19:35:38 +02:00
Matthias Maennich
beededda29 Add compatibility layer for C++11 mode
Introduce a compatibility layer for C++11 code by adding
include/abg-cxx-compat.h. abg-cxx-compat defines a new namespace
abg_compat and defines
	abg_compat::hash
	abg_compat::shared_ptr
	abg_compat::weak_ptr
	abg_compat::dynamic_pointer_cast
	abg_compat::static_pointer_cast
	abg_compat::unordered_map
	abg_compat::unordered_set
based on definitions from std::tr1 (std=gnu++98) or std:: (std=gnu++11).

I decided for introducing abg_compat:: rather than polluting abigail::
to allow an easier transition to C++11 at a later time and to not subtly
break existing code.

As the shared_ptr in C++11 defines shared_ptr::operator bool() explicit,
some locations where a shared_ptr is assigned to boolean, needed to be
adjusted to explicitly cast to bool.

	* include/abg-cxx-compat.h: new file introducing the abg_compat
	  namespace to provide C++11 functionality from either std::tr1
	  or std::
	* include/Makefile.am: Add the new abg-cxx-compat.h to source
	  distribution.
	* include/abg-comparison.h: replace std::tr1 usage by abg_compat
	  and adjust includes accordingly: likewise
	* include/abg-diff-utils.h: likewise
	* include/abg-fwd.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-libzip-utils.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-workers.h: likewise
	* src/abg-comp-filter.cc: likewise
	* src/abg-comparison-priv.h: likewise
	* src/abg-corpus.cc: likewise
	* src/abg-dwarf-reader.cc: likewise
	* src/abg-hash.cc: likewise
	* src/abg-ir.cc: likewise
	* src/abg-reader.cc: likewise
	* src/abg-suppression.cc: likewise
	* src/abg-tools-utils.cc: likewise
	* src/abg-writer.cc: likewise
	* tests/test-diff-filter.cc: likewise
	* tests/test-diff-pkg.cc: likewise
	* tests/test-read-dwarf.cc: likewise
	* tests/test-read-write.cc: likewise
	* tests/test-types-stability.cc: likewise
	* tests/test-write-read-archive.cc: likewise
	* tools/abicompat.cc: likewise
	* tools/abidiff.cc: likewise
	* tools/abidw.cc: likewise
	* tools/abilint.cc: likewise
	* tools/abipkgdiff.cc: likewise

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-07-09 18:05:28 +02:00
Matthias Maennich
c06c45f345 Update tests/.gitignore to ignore runtesttoolsutils
* tests/.gitignore: ignore runtesttoolsutils

Signed-off-by: Matthias Maennich <maennich@google.com>
2019-07-09 17:33:58 +02:00
Matthias Maennich
42cd02a9be Drop requirement to compile with GNU extensions
__gnu_cxx::stdio_filebuf is a GNU extension only available in certain
std libraries. It is not e.g. in libc++. In order to be able to compile
with using libc++, replace the usage of __gnu_cxx::stdio_filebuf with
standard C++ methods. In this case, reopen the temporary file with a
std::fstream and expose that stream rather than the previously exposed
std::iostream.

	* include/abg-tools-utils.h (get_stream): Change return type to
	  std::fstream
	* src/abg-corpus.cc: remove unused #include of ext/stdio_filebuf.h
	* src/abg-tools-utils (temp_file::priv): remove filebuf_ member,
	  and replace iostream_ by fstream_ with changing the shared_ptr
	  type accordingly
	  (temp_file::priv::priv): initialize fstream_ based on
	  temporary file name
	  (temp_file::priv::~priv): adjust destruction accordingly
	  (temp_file::is_good): test the fstream rather than the fd
	  (temp_file::get_stream): adjust return type to std::fstream
	  and adjust implementation based on the changes in temp_file::priv
	* src/Makefile.am: remove gnu extension from c++ standard flag
	* tests/Makefile.am: likewise

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-07-09 17:16:59 +02:00
Dodji Seketeli
35312fa92a [dwarf-reader] Make sure to canonicalize anonymous types
For a reason, anonymous types are not canonicalized.  I think this is
due to the fact that because they have no name,
read_context::lookup_type_from_die(die) used by maybe_canonicalize_type()
falls short in trying to canonicalize the *DIE*.

So later, at comparison time, things can be really slow because we
can't do canonical comparison; we ressort to structural comparison.

This patch ensures that even anonymous types are canonicalized.

	* src/abg-dwarf-reader.cc (maybe_canonicalize_type): Add two new
	overloads.  One that takes type_base_sptr, one that takes a
	Dwarf_Die* and type_base_sptr.  These force canonicalization for
	anonymous types.
	(build_function_type): Schedule function types for
	canonicalization.
	(build_ir_node_from_die): For struct/classes and unions, use the
	new overload of maybe_canonicalize_type to schedule
	canonicalization.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Adjust.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Adjust.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-07-08 09:50:29 +02:00
Dodji Seketeli
2209df1b90 Make abidiff --harmless show harmless changes in unions
Since the previous commit filters out harmless changes inside unions,
this one allows those changes to be reported whenever the user runs
abidiff with the --harmless option.

The patch just displays the "before" and "after" of the union because
some of the harmless changes are not tracked anymore.

Because we want to display the before and after of the union we use
the function get_class_or_union_flat_representation.  The patch adds a
"qualified_name" boolean parameter to that function so that we can
choose to display union members names in a non-qualified fashion,
which is the natural way of displaying those names in the context of a
union (or class) representation.  Because
get_class_or_union_flat_representation uses
type_or_decl_base::get_pretty_representation, the patch has also added a
"qualified_name" boolean parameter to that function so that we can
choose to display names in a non-qualified manner.

	* include/abg-fwd.h (get_class_or_union_flat_representation): Add
	a "qualified_name" boolean parameter.
	* include/abg-ir.h ({type_or_decl_base, decl_base, type_decl,
	namespace_decl, array_type_def::subrange_type, array_type_def,
	enum_type_decl, typedef_decl, var_decl, function_decl,
	function_decl::parameter, function_type, method_type, class_decl,
	union_decl}::get_pretty_representation): Likewise.
	* src/abg-ir.cc ({type_or_decl_base, decl_base, type_decl,
	namespace_decl, array_type_def::subrange_type, array_type_def, enum_type_decl,
	typedef_decl, var_decl, function_decl, function_decl::parameter,
	function_type, method_type, class_decl, union_decl,
	}::get_pretty_representation): Adjust the code to emit qualified
	or non-qualified names depending on the new "qualified_name"
	boolean parameter.
	(get_class_or_union_flat_representation): Likewise.
	* src/abg-default-reporter.cc (default_reporter::report): Use
	get_class_or_union_flat_representation with the new
	"qualified_name" boolean set to false.
	* tests/data/test-diff-dwarf/test38-union-report-0.txt: Adjust.
	* tests/test-diff-filter.cc (in_out_specs): Run the test harness
	on test-PR24731-v{0,1}.o make abidiff use the --harmless option.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-06-26 12:08:55 +02:00
Dodji Seketeli
a11a0068ea Bug 24731 - Wrongly reporting union members order change
When union data members are re-ordered, abidiff reports the
re-ordering as if it was a meaningful ABI change.

This patch teaches Libabigail to categorize that benign type layout
change as a HARMLESS_UNION_CHANGE_CATEGORY kind of change and ignore it.

	* include/abg-comp-filter.h (union_diff_has_harmless_changes):
	Declare new function and ...
	* src/abg-comp-filter.cc (union_diff_has_harmless_changes):
	... define it here.
	(categorize_harmless_diff_node): Use the new
	union_diff_has_harmless_changes here.
	* include/abg-comparison.h (HARMLESS_UNION_CHANGE_CATEGORY): Add a
	new enumerator to diff_category enum.  Adjust the value of the
	other enumerators.
	* src/abg-comparison.cc (get_default_harmless_categories_bitmap):
	Add the new HARMLESS_UNION_CHANGE_CATEGORY in here.
	(operator<<(ostream& o, diff_category c)): Support the new
	HARMLESS_UNION_CHANGE_CATEGORY.
	* tests/data/test-diff-filter/test-PR24731-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test-PR24731-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test-PR24731-v0.c: Likewise.
	* tests/data/test-diff-filter/test-PR24731-v0.o: Likewise.
	* tests/data/test-diff-filter/test-PR24731-v1.c: Likewise.
	* tests/data/test-diff-filter/test-PR24731-v1.o: Likewise.
	* tests/data/Makefile.am: Add the new test material above to
	source distribution.
	* tests/test-diff-filter.cc (in_out_spec): Add the new test input
	to this test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-06-26 11:09:43 +02:00
Dodji Seketeli
bf100fcb41 Fully account for anonymous-ness of scopes when comparing decl names
When comparing internal decl names (as part of decl comparison), we
need to take into account the fact that a given decl might be
anonymous and that it might have anonymous scopes in its tree of
containing scopes.

For instance, "__anonymous_struct__1::foo" and
"__anonymous_struct__2::foo" are considered equivalent.

So are "__anonymous_struct__1::foo::__anonymous_struct__2::bar" and
"__anonymous_struct__10::foo::__anonymous_struct__11::bar".

But "__anonymous_struct__1::bar::__anonymous_struct__2::baz" and
"__anonymous_struct__10::foo::__anonymous_struct__11::bar" are not.

This patch introduces the function tools_utils::decl_names_equal that
compares fully qualified names by taking into account anonymous
component names.

That function is thus used in the equals() function overload for
decl_base types.  Because tools_utils::decl_names_equal compares strings the
usual way (character by character) it's slower than comparing
instances of interned_string in a O(1) time.  So the patch carefully
tries to use tools_utils::decl_names_equal sparringly; that is, it
uses it only when we are looking at decls that have some anonymous
scope.  That way, we use the fast interned_string comparison most of
the time.  By doing this, we barely see any performance degradation
while running abidw --noout on a full blown vmlinux binary.

	* include/abg-ir.h (decl_base::{get_has_anonymous_parent,
	set_has_anonymous_parent,
	get_is_anonymous_or_has_anonymous_parent}): Declare new member
	functions.
	* src/abg-ir.cc (decl_base::priv::has_anonymous_parent_): Define
	new data member.
	(decl_base::priv): Initialize the new data member.
	(decl_base::{get_has_anonymous_parent, set_has_anonymous_parent,
	get_is_anonymous_or_has_anonymous_parent}): Define new member
	functions.
	(equals): In the overload for decl_base, use the new
	decl_names_equal for decls that have anonymous scopes.
	(scope_decl::add_member_decl): Propagate the
	decl_base::has_anonymous_parent_ property.
	* include/abg-tools-utils.h
	(get_anonymous_struct_internal_name_prefix)
	(get_anonymous_union_internal_name_prefix)
	(get_anonymous_enum_internal_name_prefix, decl_names_equal):
	Declare new functions.
	* src/abg-comp-filter.cc (has_harmless_name_change): Handle the
	case where the name change is actually from an anonymous name to
	another one, using the new decl_names_equal function.
	* src/abg-dwarf-reader.cc
	(get_internal_anonymous_die_prefix_name): Renamed
	get_internal_anonynous_die_base_name into this.  Use the new
	get_anonymous_{struct, union, enum}_internal_name_prefix functions
	here.
	(get_internal_anonymous_die_name, die_qualified_type_name)
	(build_enum_type, add_or_update_class_type)
	(add_or_update_union_type): Adjust.
	* src/abg-tools-utils.cc (get_anonymous_struct_internal_name_prefix)
	(get_anonymous_union_internal_name_prefix)
	(get_anonymous_enum_internal_name_prefix, decl_names_equal):
	Define new functions.
	* tests/test-tools-utils.cc: New test file.
	* tests/Makefile.am: Add new runtesttoolsutils test, built from
	test-tools-utils.cc.
	* tests/data/test-diff-dwarf/test46-rust-report-0.txt: Adjust.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-06-21 11:42:44 +02:00
Dodji Seketeli
23744b4b8e [dwarf-reader] Better use of linkage name for fn decl de-duplication
When looking at a C program, during function decl DIE de-duplication
at we can rely on linkage names of function declarations to quickly
determine if two function decls are equal, in a given binary.

This patch uses that observation to speed up function decl DIE
de-duplication.  abidw --noout vmlinux goes from 8 to 5 minutes with
this.

	* src/abg-dwarf-reader.cc (read_context::{die_is_in_c,
	die_is_in_c_or_cplusplus}): Define new member functions.
	(fn_die_equal_by_linkage_name): Define new static function.
	(compare_dies): In the case for for DW_TAG_subprogram, use the new
	fn_die_equal_by_linkage_name.
	* tests/data/test-annotate/test15-pr18892.so.abi: Adjust.
	* tests/data/test-annotate/test21-pr19092.so.abi: Adjust.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Adjust.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-06-13 18:28:12 +02:00
Dodji Seketeli
6149fb02d0 [dwarf-reader] Re-use function types inside a given TU
Whenever we see a function type inside a translation unit, if it
matches one that has already been seen -- i.e, one that has the same
textual representation -- we should be able to re-use that same
function type without having to compare their types to be sure they
are the same, as part of the type canonicalization process.

This slittly increases analysis speed (by a few tens of seconds on a
total of 8 minutes) by decreasing the load on type canonicalization
when anlyzing vmlinux.  It also slightly reduces memory consumption,
so I am getting it in for now.

	* src/abg-dwarf-reader.cc (istring_fn_type_map_type): Declare new
	typedef.
	(die_is_function_type): Define new static function.
	(read_context::per_tu_repr_to_fn_type_maps_): Define new data
	member ...
	(read_context::per_tu_repr_to_fn_type_maps): ... and its accessor.
	(read_context::{associate_die_repr_to_fn_type_per_tu,
	lookup_fn_type_from_die_repr_per_tu}): Define new member
	functions.
	(build_function_type): Use the new
	read_context::lookup_fn_type_from_die_repr_per_tu and
	read_context::associate_die_repr_to_fn_type_per_tu functions,
	instead of read_context::lookup_type_from_die.
	* tests/data/test-annotate/test13-pr18894.so.abi: Adjust.
	* tests/data/test-annotate/test14-pr18893.so.abi: Adjust.
	* tests/data/test-annotate/test21-pr19092.so.abi: Adjust.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Adjust.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Adjust.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Adjust.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-06-13 18:28:11 +02:00
Dodji Seketeli
073608f47d Take anonymous scopes into account when comparing decls
This is another attempt at handling anonymous decls comparison.  It's
not the full blown method that I'd like, but this one seems to be fast
enough.  In this method, we take the immediate scope (and whether it's
anonymous or not) of the anonymous decl into account.

	* include/abg-interned-str.h (interned_string::clear): Add new
	member function.
	* src/abg-ir.cc (equals): In the overload for decl_base, consider
	the scope of the current (anonymous) decl.  If that scope is
	anonymous then take that into account as well.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt:
	Adjust.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-06-13 17:54:45 +02:00
Matthias Maennich
948f27480f abg-writer: Refactor write_corpus API
Introduce a new overload for write_corpus that follows the parameter
order context, object (i.e. corpus), indent.

Deprecate all other overloads that were part of the API and mostly
forward them to the new overload. That effort is made to ensure
write_context is always provided. write_context allows access to all
options that influence the output format.

	* include/abg-writer.h (write_corpus): Introduce new overload
	write_corpus(ctxt, corpus, indent) and deprecate all others.
	* src/abg-writer.cc (write_corpus): Likewise for the definitions
	and adjust.
	* tests/test-read-dwarf.cc (test_task::perform): Use the new
	write_corpus which requires a write_context.
	* tools/abidw.cc (load_corpus_and_write_abixml, ): Likewise.
	* tools/abilint.cc (main): Likewise. Also simplify logic around the
	locations as they now can be expressed with less code.

Signed-off-by: Matthias Maennich <maennich@google.com>
2019-05-22 14:33:45 +02:00
Dodji Seketeli
f754d81116 Bug 24552 - abidiff fails comparing a corpus against a corpus group
In this problem report, the issue is that when comparing two corpus
groups, especially when looking up function/variable symbols, the
get_fun_symbol_map() and get_var_symbol_map() member functions used
are corpus::get_{fun,var}_symbol_map, rather than
corpus_group::get_{fun, var}_symbol_map.  Note that the type
corpus_group inherits from the type corpus.  That leads to unexpected
comparison results, especially for symbols.

This patch fixes this by making the corpus::get_{fun, var}_symbol_map
member function be virtual and by using it during the lookup of
function/variable symbols.  That way, the right symbol map gets used.

	* include/abg-corpus.h (corpus{_group}::get_{fun,
	var}_symbol_map): Make these member functions virtual.
	* src/abg-corpus.cc (corpus::lookup_{function, variable}_symbol):
	Use the virtual corpus::get_{fun, var}_symbol_map() member
	function to get the symbols of the current corpus or corpus_group.
	* tests/data/Makefile.am: Add the new test input material below to
	source distribution.
	* tests/data/test-abidiff/test-PR24552-report0.txt: New test input.
	* tests/data/test-abidiff/test-PR24552-v0.abi: Likewise.
	* tests/data/test-abidiff/test-PR24552-v1.abi: Likewise.
	* tests/test-abidiff.cc (main): Support comparing corpus groups.
	(specs): Add the new test inputs to the harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-05-16 18:10:08 +02:00
Dodji Seketeli
2cf9a18e8c Better handle several anonymous types of the same kind
This is a follow-up patch for the commit:

   43d56de Handle several member anonymous types of the same kind

It allows support for severan anonymous types even when these are not
members of a class/unions.

The patch introduces the concept of a scoped name.  It's a qualified
name for a decl made of the name of the decl appended to the
*unqualified* name of its scope.  Unlike for qualified names, the
scoped name won't have a "__anonymous_*__" string in its name if its
directly containing scope is not anonymous; a qualified name might
still have that string in its name because the decl has a parent scope
(not necessarily its directly containing scope though) that is
anonymous.

The patch goes on to update the logic for comparison of decls that are
anonymous.  For a decl which direct scope is *NOT* anonymous, the
scoped name is what's used in the comparison.  Otherwise, only the
name of the decl is used.

The patch also updates how we detect changes in data members and
member types, in the comparison engine.  It now uses the names of the
data members, rather than their qualified name.  This is in the scope
of the current class/union anyway.  The improvement is that the fact
that the class/union itself is anonymous (even if its anonymous name
changes to another anonymous name) won't have any spurious impact on
the detection of name change of the members.

The patch considers the change of an anonymous decl name which
anonymous name changes to another anonymous name as being harmless.

The patch updates the logic of category propagation in the comparison
engine.  Although a public typedef to private underlying type needs to
stay public and thus not propagate the PRIVATE_TYPE_CATEGORY from its
child diff node to himself, it still needs to suppress the changes to
the private underlying diff node that were suppressed (because of the
private-ness), unless that typedef has local changes.

	* include/abg-ir.h (decl_base::get_scoped_name): Declare new
	member function.
	(scope_decl::get_num_anonymous_member_{classes, unions, enums}):
	Declare new virtual member functions.
	(class_decl::get_num_anonymous_member_{classes, unions, enums}):
	Adjust to make these virtual.  It's not necessary but I feel
	redundancy is a kind of self-documentation here.
	* src/abg-comp-filter.cc (has_harmless_name_change): Consider
	anonymous name changes as harmless.
	* src/abg-comparison.cc
	(class_or_union_diff::ensure_lookup_tables_populated): Consider
	the names of the members rather than their qualified names.
	(suppression_categorization_visitor::visit_end): Suppress the
	changes to the private underlying diff node that were suppressed
	because of the private-ness, unless that typedef has local
	changes.
	* src/abg-dwarf-reader.cc (build_enum_type)
	(add_or_update_class_type, add_or_update_union_type): Handle
	anonymous types in namespaces as well, not just in class/unions.
	* src/abg-ir.cc (decl_base::priv::scoped_name_): Define new data
	member.
	(decl_base::get_scoped_name): Define new member function.
	(equals): For the decl_base overload, use scoped name in the
	comparison, unless the decl belongs to an anonymous type.  For the
	class_or_union_diff, only consider scoped_name during comparison.
	Avoid name comparison between anonymous types.
	(scope_decl::get_num_anonymous_member_{classes, unions, enums}):
	Define new member functions.
	(types_have_similar_structure): Do not compare names between
	anonymous types.
	(qualified_name_setter::do_update): Update scoped names too.
	* tests/data/test-abidiff/test-PR18791-report0.txt: Adjust.
	* tests/data/test-annotate/libtest23.so.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-diff-dwarf/test43-PR22913-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test46-rust-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt:
	Likewise.
	* tests/data/test-diff-filter/test33-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test44-anonymous-data-member-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64--libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Likewise.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Likewise.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-05-09 15:19:05 +02:00
Dodji Seketeli
43d56de89b Handle several member anonymous types of the same kind
When there are several anonymous types (e.g, anonymous classes, unions
or enums) in a given class or union, libabigail's internals do
struggle.

An anonymous class, for instance, is named __anonymous_struct__.  When
there are more than one of these inside a given class, then we can't
name and look them up, because they all have the same name.

Incidentally, when add_or_update_class_type completes a class type
that was initially constructed before, it fails to determine that an
anonymous member type of that class was already present in that
context.  It thus wrongly duplicates anonymous structs/unions/enums in
there and that leads to spurious textual (abixml) representation
differences later, where duplicated anonymous member types would
appear intermittently, depending on the order in which the class was
built.

This patch addresses this general issue by naming anonymous member
types in a way that allows several of them to exist. That is, if there
are two anonymous structs in a class, they are going to be named
__anonymous_struct__ and __anonymous_struct__1.  We do follow a
similar scheme for anonymous unions and enums. This is handled by the
DWARF reader that builds the internal representation.

While looking at this issue, I also fixed a tangent bug; some DWARF
emitters wrongly *define* types in the scope of a
DW_TAG_subroutine_type or DW_TAG_array_type.  We handle that by
actually defining those types in the scope of that subroutine or
array.  But then it appears that if that scope itself a class and if
the type defined is an anonymous type, then putting that anonymous
type in the class scope might interfere with the *naming* of the
existing legit anonymous types of that scope.  I decided to put those
anonymous types in the containing namespace instead.  We'll see how
that goes in real time use.

The patch also updates lots of existing tests and adds a new one.

	* include/abg-ir.h
	(class_or_union::get_num_anonymous_member_{classes, unions,
	enums}): Declare new member functions.
	* src/abg-dwarf-reader.cc (get_internal_anonynous_die_base_name)
	(build_internal_anonymous_die_name)
	(get_internal_anonymous_die_name, is_anonymous_type_die): Define
	new static functions.
	(die_qualified_type_name): Use the new
	get_internal_anonymous_die_name.
	(get_scope_for_die): Fix this to put anonymous types that were
	wrongly emitted into the scope of DW_TAG_subroutine_type or
	DW_TAG_array_type by buggy DWARF emitters into the enclosing
	namespace, rather than into the enclosing class/union.
	(build_enum_type): Take the scope of the enum to have a chance to
	properly name potential anonymous enums.
	(lookup_class_typedef_or_enum_type_from_corpus): Take an anonymous
	member type index for when the DIE we are lookup up represents an
	anonymous type.  Support proper building of the internal anonymous
	name of the anonymous type we are lookup up.
	(add_or_update_class_type): Use the new
	get_internal_anonynous_die_base_name and
	build_internal_anonymous_die_name functions.  Support making sure
	that the anonymous member type we are adding to the class wasn't
	already there, especially for cases where we are updating a class
	type.
	(add_or_update_union_type): Use the new
	get_internal_anonynous_die_base_name and
	build_internal_anonymous_die_name functions.
	(build_ir_node_from_die): Adjust the use of build_enum_type to
	pass it the scope of the enum type we are building.
	* src/abg-ir.cc	(lookup_union_type): Add a new overload.
	(lookup_class_or_typedef_type): Use the new overload of
	lookup_union_type above to support looking up union types too.
	(class_or_union::get_num_anonymous_member_{classes, unions,
	enums}): Define new member functions.
	* src/abg-reporter-priv.cc (represent): Detect when anonymous
	types of anonymous data members have their internal names change,
	probably because anonymous member types were inserted in the scope.
	* tests/data/Makefile.am: Add the new test-anonymous-members-0.*
	test input files to the source distribution.
	* tests/data/test-annotate/test-anonymous-members-0.cc: New test
	input file.
	* tests/data/test-annotate/test-anonymous-members-0.o: Likewise.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Adjust.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt
	* 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-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test12-pr18844.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/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/test-annotate.cc (int_out_specs): Add the new test inputs
	to this test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-05-07 14:31:16 +02:00
Dodji Seketeli
eafa097433 Use canonical types hash maps for type IDs in abixml writer
This patch stores canonical types in the hash maps that are used in
the abixml writer to compute the type IDs.  This limits the
possibility that two types that are equivalent (especially when one is
a declaration-only class) end-up in the same abixml.

	* src/abg-writer.cc (write_context::{type_has_existing_id,
	get_id_for_type}): Save the canonical type of the type in the map,
	not the type itself.
	(write_context::{type_is_emitted}): Use the canonical type rather
	than the type itself.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-04-24 17:52:39 +02:00
Dodji Seketeli
04d61a726d Don't try to de-duplicate all anonymous struct DIEs
Trying to de-duplicate anonymous struct DIEs can lead to subtle
issues, because there can be two different naming typedefs designating
two anonymous structs that are equivalent, in the same translation
unit.  In that case, de-duplicating the two leaf anonymous structs
DIEs leads to non-resolvable conflict.

This patch avoids de-duplicating anonymous structs DIEs and rather
de-duplicates (naming) typedefs.

	* include/abg-fwd.h (is_typedef): Remove the overloads for
	type_base_sptr and decl_base_sptr.  Replace those with an overload
	for type_or_decl_base_sptr.
	* src/abg-ir.cc (is_typedef): Do the same for the definitions.
	* src/abg-dwarf-reader.cc (add_or_update_class_type)
	(add_or_update_union_type): Do not de-duplicate anonymous
	struct/union DIEs.
	(build_typedef_type): Try to de-duplicate typedefs DIEs.
	* tests/data/test-annotate/test17-pr19027.so.abi: Adjust.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-04-24 16:59:35 +02:00
Dodji Seketeli
451d34d1ad Canonicalize types non tied to any DWARF DIE
During DWARF reading, it can happen that some types are created that
are not tied to a given DIE.  This happens for instance when editing
the internal representation of types to better reflect the intent of
the code rather than the letter of the code; more precisely this
happens when a qualified array is edited to represent an array of
qualified elements, for instance.  In that case, the qualified element
type is created by the DWARF analyser.  And in the present incarnation
of the code, we forget to canonicalize that type.

The fact that that type is not canonicalized leads to cases where two
equivalent types can still be present in a translation unit in the
resulting abixml representation, without the abixml writer noticing
it.  That duplication can lead to unnecessary cycles in the type graph
where passes can either take one side or the other of the cycle; and
that leads to subtle heisen-changes in the emitted abixml representation.

This patch thus canonicalizes those newly created types.

	* src/abg-dwarf-reader.cc
	(read_context::extra_types_to_canonicalize_): Add new data member.
	(read_context::{initialize, clear_types_to_canonicalize}): Adjust.
	(read_context::extra_types_to_canonicalize): Create new accessor.
	(read_context::schedule_type_for_late_canonicalization): Add new
	overload for type_base_sptr.
	(read_context::perform_late_type_canonicalizing): Perform the
	canonicalization of the types created by the DWARF analyzer, but
	that are not tied to any DIE.
	(maybe_strip_qualification): Take a read_context&.  Schedule newly
	created types (during type edition) for late canonicalization.
	(build_ir_node_from_die): Adjust the call to
	maybe_strip_qualification to pass a read_context.
	* tests/data/test-annotate/test15-pr18892.so.abi: Adjust.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test17-pr19027.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.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-04-24 16:28:42 +02:00
Matthias Maennich via libabigail
b01918eb18 Update .gitignore files to ignore typical dev side products
Add / update .gitignore files for tests/ and tools to ignore
binaries, logs, traces typically produced during development.

 * tests/.gitignore: exclude tests binaries and test results
 * tools/.gitignore: update to ignore produced binaries

Signed-off-by: Matthias Maennich <maennich@google.com>
2019-04-16 16:32:52 +02:00
Matthias Maennich via libabigail
eec8e69b7d abilint: fix return types bool -> int
Returning bool literals from main can be misleading. Returning booleans
maps to (by convention):

   return false -> converted to 0 -> rc=0 considered SUCCESS
   return true  -> converted to 1 -> rc=1 considered FAILURE

Compiling with clang also emits:

  abilint.cc:258:7: warning: bool literal returned from 'main' [-Wmain]
      return true;
      ^      ~~~~

The issues can be addressed by consistently returning integers as also
done in all other mains across the project.

Same issue applies to print-diff-tree.cc.

 * tools/abilint.cc: return int in main rather than bool.
 * tests/print-diff-tree.cc: Likewise.

Signed-off-by: Matthias Maennich <maennich@google.com>
2019-04-16 16:11:01 +02:00
Dodji Seketeli
286cadf841 Bug 24430 - Fold away const for array types
In C and C++ the qualifiers of a qualified array type apply to the
element type of said array.

In this particular problem report, GCC and Clang emit DWARF that
represent the qualifiers either on the array type, or on the element
type.  Quoting the test of the bug:

    Given the following example:

	struct test {
	  const char asdf[4];
	};

	void func(struct test arg) {}

    abidiff says:

     1 function with some indirect sub-type change:

       [C]'function void func(test)' at test.c:5:1 has some indirect sub-type
     changes:
	 parameter 1 of type 'struct test' has sub-type changes:
	   type size hasn't changed
	   1 data member change:
	    type of 'const char test::asdf[4]' changed:
	      entity changed from 'const char[4]' to 'const char[4] const'

This is because GCC represents the array as const array of const
signed char, whereas clang represents it as an array of const signed
char.

In this patch, libabigail's DWARF reader detects qualified array types
and appropriately qualifies the array element type, instead of
qualifying the array type.  The patch accordingly adjusts the various
regression tests and adds a new test which comes from the problem
report.

	* include/abg-fwd.h (is_array_of_qualified_element): Declare 2
	overloads of this function.
	(re_canonicalize): Declare a new function.
	* include/abg-ir.h (class {decl_base, type_base}): Declare
	re_canonicalize as a friend of these classes.
	* src/abg-dwarf-reader.cc (maybe_strip_qualification): Detect
	qualified array types and appropriately qualifies the array
	element type, instead of qualifying the array type itself.
	Re-canonicalize the resulting type if necessary.
	* src/abg-ir.cc (is_array_of_qualified_element): Define 2
	overloads of this function.
	(re_canonicalize): Define new function.
	* tests/data/Makefile.am: The two new test binary input files
	PR24430-fold-qualified-array-clang and
	PR24430-fold-qualified-array-gcc to source distribution, as well
	as the expected reference output.
	* tests/data/test-annotate/test15-pr18892.so.abi: Adjust.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-diff-filter/PR24430-fold-qualified-array-clang:
	New binary test input coming from the bug report.
	* tests/data/test-diff-filter/PR24430-fold-qualified-array-gcc:
	Likewise.
	* tests/data/test-diff-filter/PR24430-fold-qualified-array-report-0.txt:
	Expected reference abi difference.
	* tests/data/test-diff-filter/test33-report-0.txt: Adjust.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/test-diff-filter.cc: Add the new binary test input to this
	test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-04-10 13:02:36 +02:00
Dodji Seketeli
80bbf3dd62 Fix "Add test for the fix for PR24410"
Oops, seems like I forgot to add some of the binaries.

There you go.

	* tests/data/test-diff-pkg/PR24410-new/poppler-debuginfo-0.73.0-8.fc30.x86_64.rpm:
	Really add this.
	* tests/data/test-diff-pkg/PR24410-new/poppler-qt5-0.73.0-8.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/PR24410-new/poppler-qt5-debuginfo-0.73.0-8.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/PR24410-new/poppler-qt5-devel-0.73.0-8.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/PR24410-old/poppler-debuginfo-0.73.0-4.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/PR24410-old/poppler-qt5-0.73.0-4.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/PR24410-old/poppler-qt5-debuginfo-0.73.0-4.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/PR24410-old/poppler-qt5-devel-0.73.0-4.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/PR24410-report-0.txt: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-04-09 11:16:12 +02:00
Dodji Seketeli
e54191eac9 Add test for the fix for PR24410
PR24410 was fixed by these recent commits:

    1b83138 Propagate private type diff category through refs/qualified type diffs
    dc84fee Fix anonymous union constructed under the wrong context
    522ac25 Internal pretty repr of union cannot be flat representation

But then I forgot to add a regression test for that issue.

This patch does that.

	* tests/data/test-diff-pkg/PR24410-new/poppler-debuginfo-0.73.0-8.fc30.x86_64.rpm:
	Add new test input.
	* tests/data/test-diff-pkg/PR24410-new/poppler-qt5-0.73.0-8.fc30.x86_64.rpm:
	Add new test input.
	* tests/data/test-diff-pkg/PR24410-new/poppler-qt5-debuginfo-0.73.0-8.fc30.x86_64.rpm:
	Add new test input.
	* tests/data/test-diff-pkg/PR24410-new/poppler-qt5-devel-0.73.0-8.fc30.x86_64.rpm:
	Add new test input.
	* tests/data/test-diff-pkg/PR24410-old/poppler-debuginfo-0.73.0-4.fc30.x86_64.rpm:
	Add new test input.
	* tests/data/test-diff-pkg/PR24410-old/poppler-qt5-0.73.0-4.fc30.x86_64.rpm:
	Add new test input.
	* tests/data/test-diff-pkg/PR24410-old/poppler-qt5-debuginfo-0.73.0-4.fc30.x86_64.rpm:
	Add new test input.
	* tests/data/test-diff-pkg/PR24410-old/poppler-qt5-devel-0.73.0-4.fc30.x86_64.rpm:
	Add new test input.
	* tests/data/test-diff-pkg/PR24410-report-0.txt: Add new test
	input.
	* tests/data/Makefile.am: Add the test input above to source
	distribution.
	* tests/test-diff-pkg.cc: Make this test harness use the new input
	rpms above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-04-09 11:02:53 +02:00
Dodji Seketeli
1b831382d0 Propagate private type diff category through refs/qualified type diffs
This patch is the third of the series:

    Internal pretty repr of union cannot be flat representation
    Fix anonymous union constructed under the wrong context
    Propagate private type diff category through refs/qualified type diffs

The intent of this series is to fix the bug:

    https://sourceware.org/bugzilla/show_bug.cgi?id=24410
    "Empty change report emitted for libpoppler-qt5.so.1.18.0"

We (mistakenly) don't propagate private type diff categories through
reference and qualified type diffs.  This leads to some diff nodes not
being suppressed just because they are private type diffs which
category weren't properly propagated.

This patch fixes this.

Note that the tests updated in this patch reflect the regression tests
changes needed for the entire set of 3 patches.

	* src/abg-comparison.cc
	(suppression_categorization_visitor::visit_end): Propagate
	suppressed and private type diff categories for reference and
	qualified types.  For qualified types, make sure they don't have
	local changes.  Even when there are no local changes, do not
	propagate private diff categories to typedefs.
	* tests/data/test-annotate/test17-pr19027.so.abi: Adjust.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Likewise.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test17-pr19027.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>
2019-04-08 11:30:45 +02:00
Dodji Seketeli
5bb7194b0a Bug 24378 - DW_TAG_subroutine_type as a DIE scope causes infinite loop
GCC 4.3.2 wrongly emits some type definition DIEs in the scope of a
DW_TAG_subroutine_type.  Whenever the DWARF reader tries to get the
scope of a DIE during the computation of the pretty name of a type DIE
which scope is (wrongly) emitted as being a DW_TAG_subroutine_type
things end-up in an infinite loop.

This patch makes get_scope_die to look through the
DW_TAG_subroutine_type to return the proper scope instead, just like
what we already do for DW_TAG_subprogram and DW_TAG_array_type.

	* src/abg-dwarf-reader.cc (get_scope_die): Look through
	DW_TAG_subroutine_type to get the scope of a given DIE.
	* tests/data/Makefile.am: Add the two new files below to source
	distribution.
	* tests/data/test-read-dwarf/PR24378-fn-is-not-scope.abi: New
	reference test output.
	* tests/data/test-read-dwarf/PR24378-fn-is-not-scope.o: New binary
	test input.
	* tests/test-read-dwarf.cc (in_out_specs): Add the new test input
	to the test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-03-25 14:46:31 +01:00
Dodji Seketeli
fc02416b28 PR24257 - Handle DW_TAG_typedef with no underlying type
In this problem report the DWARF reader fails to recognize a
DW_TAG_typedef DIE with no underlying type as a "typedef void foo"
type.

This patch fixes that and adjusts the testsuite accordingly.

	* src/abg-dwarf-reader.cc (build_typedef_type): DW_TAG_typedef
	with no underlying type means typedef void foo.
	* tests/data/test-annotate/test15-pr18892.so.abi: Adjust.
	* 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/test10-pr18818-gcc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Likewise.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-03-21 17:31:12 +01:00
Dodji Seketeli
c00e2120b9 Bug 24188 - Assertion failed while analysing a Fortran binary
While analysing a Fortran binary the DWARF reader performs DIE
de-duplication.  During that process, the compare_dies function
stumbles accross the a DIE of the DW_TAG_string_type kind.  And it
doesn't know how to compare those DIEs.  And this leads to an abort of
the abipkgdiff program, in particular.

DW_TAG_string_type DIEs do have a DW_AT_string_length attribute which
value is a location expression that does not resolve to a constant
value.  In general, we cannot evaluate those expressions in a static
context like in Libabigail because we lack things like register values
which are dynamic in nature.

So, I decided for now to consider that two DW_TAG_string_type seen at
different DWARF offsets are considered to be different for now.  This
pessimises DIEs de-duplication for types that contain
DW_TAG_string_type as their subtypes, but at least this is a basic
support for DW_TAG_string_type.

Tested with the RPMs on which abipkgdiff was failing.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>

	* src/abg-dwarf-reader.cc (compare_as_type_dies): Handle
	DW_TAG_string_type DIEs here.
	(compare_dies): Handle DW_TAG_string_type DIEs by using
	compare_as_type_dies.
	* tests/data/test-diff-pkg/netcdf-fortran-debuginfo-4.4.4-10.fc29.x86_64.rpm:
	New test RPM.
	* tests/data/test-diff-pkg/netcdf-fortran-debuginfo-4.4.4-11.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/netcdf-fortran-mpich-4.4.4-10.fc29.x86_64-4.4.4-11.fc30.x86_64-report-0.txt:
	New expected test reference output.
	* tests/data/test-diff-pkg/netcdf-fortran-mpich-4.4.4-10.fc29.x86_64.rpm:
	New test RPM.
	* tests/data/test-diff-pkg/netcdf-fortran-mpich-4.4.4-11.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/netcdf-fortran-mpich-debuginfo-4.4.4-10.fc29.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/netcdf-fortran-mpich-debuginfo-4.4.4-11.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/netcdf-fortran-mpich-devel-4.4.4-10.fc29.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/netcdf-fortran-mpich-devel-4.4.4-11.fc30.x86_64.rpm:
	Likewise.
	* tests/data/Makefile.am: Add the new test input material above to
	source distribution.
	* tests/test-diff-pkg.cc (in_out_spec): Add the new test RPMs
	above to the set of RPMs to use as test input.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-02-08 10:43:59 +01:00
Dodji Seketeli
84ec784743 Bug 24157 - Wrong support of Ada ranges
In this problem report, the DWARF reader comes across an ADA subrange
which lower bound is a negative signed integer.  The problem is that
the internal representation of libabigail expects the bounds of the
subrange to be unsigned integer.  This incompatibility leads to an
assertion failure.

Further down the road I realized that the function
types_have_similar_structure doesn't support subrange types.

This patch thus introduces a new
array_type_def::subrange_type::bound_value class that captures the
signedness of the bound value.  This allows the internal
representation to keep the sign information of the bound value, and
yet be able to treat the bound value as either a signed or unsigned
value depending on the contexts.

The patch also extends the function types_have_similar_structure to
make it support subrange types.

	* include/abg-ir.h (array_type_def::subrange_type::bound_value):
	Define new class.
	(array_type_def::subrange_type::subrange_type): Adjust to use the
	new bound_value type for bound values.
	(array_type_def::subrange_type::{get_upper_bound, get_lower_bound,
	set_upper_bound, set_lower_bound}): Return or take int64_t rather
	than size_t.
	(array_type_def::subrange_type::get_length): Return uint64_t
	rather than size_t.
	* src/abg-dwarf-reader.cc (die_signed_constant_attribute)
	(die_constant_attribute, die_attribute_has_form)
	(die_attribute_is_signed, die_attribute_is_unsigned)
	(die_attribute_has_no_signedness): Define new static functions.
	(get_default_array_lower_bound): Return uint64_t rather than int.
	(build_subrange_type): Use the new
	array_type_def::subrange_type::bound_value type for bound values.
	Use the new die_constant_attribute function, rather than
	die_unsigned_constant_attribute to fecth the bound values.
	* src/abg-ir.cc
	(array_type_def::subrange_type::bound_value::{bound_value,
	get_signedness, set_signedness, get_signed_value,
	get_unsigned_value, set_unsigned, set_signed}): Define new member
	functions.
	(array_type_def::subrange_type::priv::{lower_bound_,
	upper_bound}): Use the new class bound_value.
	(array_type_def::subrange_type::priv::priv): Adjust to use the new
	bound_value class to hold bound values.
	(array_type_def::subrange_type::subrange_type): Likewise.
	(array_type_def::subrange_type::{get_upper_bound, get_lower_bound,
	set_upper_bound, set_lower_bound}): Return or take int64_t rather
	than size_t.
	(array_type_def::subrange_type::get_length): Return uint64_t
	rather than size_t.
	(types_have_similar_structure): Handle array_type_def::subrange_type
	* src/abg-reader.cc (build_subrange_type): Use the new
	array_type_def::subrange_type::bound_value to hold bound values.
	* tests/data/test-diff-pkg/GtkAda-debuginfo-2.24.2-29.fc29.x86_64.rpm:
	New binary RPM as test input.
	* tests/data/test-diff-pkg/GtkAda-debuginfo-2.24.2-30.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/GtkAda-devel-2.24.2-29.fc29.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/GtkAda-devel-2.24.2-30.fc30.x86_64.rpm:
	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:
	New expected test output.
	* tests/data/test-diff-pkg/GtkAda-gl-2.24.2-29.fc29.x86_64.rpm:
	New binary RPM as test input.
	* tests/data/test-diff-pkg/GtkAda-gl-2.24.2-30.fc30.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/GtkAda-gl-debuginfo-2.24.2-29.fc29.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/GtkAda-gl-debuginfo-2.24.2-30.fc30.x86_64.rpm:
	Likewise.
	* tests/data/Makefile.am: Add the new test material above to source
	distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the new input testing
	RPMs in here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-02-07 11:21:34 +01:00
Dodji Seketeli
3826ab5308 Bug 24139 - Support suppressing some enumerator changes
This patch teaches the suppression specification subsystem how to
ignore changes of some enumerators in particular.

The patch adds a new property to the [suppress_type] section which is:

    changed_enumerators = enumerator1, enumerator2, etc

This property is taken into accound iff the current suppress_type does
have the 'type_kind = enum' property.

Changes to enum types that match the new 'changed_enumerators'
property are suppressed.

	* doc/manuals/libabigail-concepts.rst: Document the new
	'changed_enumerators' property.
	* include/abg-suppression.h
	(type_suppression::{g, s}et_changed_enumerator_names): Declare two
	new member functions.
	* src/abg-suppression-priv.h
	(type_suppression::priv::changed_enumerator_names_): Add a new
	data member.
	* src/abg-suppression.cc
	(type_suppression::{g,s}et_changed_enumerator_names): Define two
	new member functions.
	(type_suppression::suppresses_diff): Support evaluating the new
	'changed_enumerators = <vector of changed enumerators>'.
	(read_type_suppression): Read the new list
	property'changed_enumerators" and store it into the
	type_suppression using the new
	type_suppression::set_changed_enumerator_names ().
	* tests/data/test-diff-suppr/libtest4{0,1}-enumerator-changes-v{0,1}.so:
	Add new test inpujts.
	* tests/data/test-diff-suppr/test4{0,1}-enumerator-changes-0.suppr:
	Add a new suppr spec for this new test.
	* tests/data/test-diff-suppr/test4{0,1}-enumerator-changes-report-0.txt:
	The default report.
	* tests/data/test-diff-suppr/test4{0,1}-enumerator-changes-v{0,1}.cc:
	Add Source code of libtest4{0,1}-enumerator-changes-v{0,1}.so.
	* tests/data/Makefile.am: Add the test files above to source
	distribution.
	* tests/test-diff-suppr.cc: Add the test input files above to the
	harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-01-31 09:20:06 +01:00
Dodji Seketeli
7d639aef70 Bug 20175 - Classify CV qual changes in variable type as harmless
When the type of a variable changes and that change is only a CV qual
change, we want libabigail to automatically classify that change as
being harmless.

This patch thus introduces a new VAR_TYPE_CV_CHANGE_CATEGORY change
category (enumerator of the abigail::comparison::diff_category enum)
for this kind of changes and classifies that category as being
harmless.

The patch then detects diff nodes that carry CV qualifiers change on
variable types and flags them as belonging to the new
VAR_TYPE_CV_CHANGE_CATEGORY.

	* include/abg-comparison.h (VAR_TYPE_CV_CHANGE_CATEGORY): Add new
	enumerator to diff_category enum.
	(EVERYTHING_CATEGORY): Update this enumerator.
	* src/abg-comp-filter.cc (type_diff_has_cv_qual_change_only):
	Support array diff nodes carrying a cv qual change on the element
	type.
	(has_var_type_cv_qual_change): Define new static function.
	(categorize_harmless_diff_node): Use the new
	has_var_type_cv_qual_change to categorize variable diff node with
	cv qual change on its type as harmless.
	* src/abg-comparison.cc
	(get_default_harmless_categories_bitmap): Update this.
	(operator<<(ostream& o, diff_category c)): Likewise.
	* include/abg-ir.h (equals_modulo_cv_qualifier): Declare new ...
	* src/abg-ir.cc (equals_modulo_cv_qualifier): ... function.
	* 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:
	Update expected test output.
	* 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/Makefile.am: Add the new test material below to
	source distribution.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	New expecte test output.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64.rpm: New
	test input.
	* tests/data/test-diff-pkg/nss-3.24.0-1.0.fc23.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/nss-debuginfo-3.23.0-1.0.fc23.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/nss-debuginfo-3.24.0-1.0.fc23.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/nss-devel-3.23.0-1.0.fc23.x86_64.rpm: Likewise.
	* tests/data/test-diff-pkg/nss-devel-3.24.0-1.0.fc23.x86_64.rpm: Likewise.
	* tests/test-diff-pkg.cc (in_out_specs): Add the test input above
	to the test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-01-25 11:54:29 +01:00
Dodji Seketeli
9485822670 Properly add the new rust tests to EXTRA_DIST
* tests/data/Makefile.am: Add the new rust tests to
           EXTRA_DIST.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-01-24 13:48:26 +01:00
Dodji Seketeli
4d40cc9986 Conditionalize the Rust support regression test
* tests/test-diff-dwarf.cc: Run the rust support regression test
	only if we support Rust on the platform.
	* tests/test-utils.h: Include config.h.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-01-24 11:06:57 +01:00
Dodji Seketeli
6e9b2ae423 Fix a typo in the recent Rust support and update regression tests
* configure.ac: Fix the typo HAS_LANG_Rust into HAS_DW_LANG_Rust.
	* tests/data/test-diff-dwarf/test46-readme.txt: Add new file to
	the test suite.
	* tests/data/test-diff-dwarf/test46-rust-libone.so: Likewise.
	* tests/data/test-diff-dwarf/test46-rust-libtwo.so: Likewise.
	* tests/data/test-diff-dwarf/test46-rust-report-0.txt: Likewise.
	* tests/test-diff-dwarf.cc (in_out_specs): Update the tests array
	to compare the two new binaries included above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-01-24 10:35:05 +01:00
Dodji Seketeli
ad8732316a Bug 23044 - Assertions with side effects
There are lots of spots in libabigail's source code where the argument
of the assert() call does have side effects.  This is a problem
because when the code is compiled with the NDEBUG macro defined, the
assert call does nothing, so the side effects of its argument are then
suppressed, changing the behaviour of the program.

To handle this issue, this patch introduces the ABG_ASSERT macro which
is a wrapper around the assert call that enable the use of side
effects in its argument.  The patch now uses that ABG_ASSERT macro
instead of using the assert call directly.

The patch also makes it so that the configure option accepts the
--disable-assert option so that the user can build libabigail with the
NDEBUG macro defined.

Tested by running the testsuite with and without the --disable-assert
option to configure.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-01-09 18:36:56 +01:00
Dodji Seketeli
047342467c Update copyright for 2019
* include/abg-comp-filter.h: Update copyright for 2019
	* include/abg-comparison.h: Update copyright for 2019
	* include/abg-config.h: Update copyright for 2019
	* include/abg-corpus.h: Update copyright for 2019
	* include/abg-diff-utils.h: Update copyright for 2019
	* include/abg-dwarf-reader.h: Update copyright for 2019
	* include/abg-fwd.h: Update copyright for 2019
	* include/abg-hash.h: Update copyright for 2019
	* include/abg-ini.h: Update copyright for 2019
	* include/abg-interned-str.h: Update copyright for 2019
	* include/abg-ir.h: Update copyright for 2019
	* include/abg-libxml-utils.h: Update copyright for 2019
	* include/abg-libzip-utils.h: Update copyright for 2019
	* include/abg-reader.h: Update copyright for 2019
	* include/abg-reporter.h: Update copyright for 2019
	* include/abg-sptr-utils.h: Update copyright for 2019
	* include/abg-suppression.h: Update copyright for 2019
	* include/abg-tools-utils.h: Update copyright for 2019
	* include/abg-traverse.h: Update copyright for 2019
	* include/abg-viz-common.h: Update copyright for 2019
	* include/abg-viz-dot.h: Update copyright for 2019
	* include/abg-viz-svg.h: Update copyright for 2019
	* include/abg-workers.h: Update copyright for 2019
	* include/abg-writer.h: Update copyright for 2019
	* src/abg-comp-filter.cc: Update copyright for 2019
	* src/abg-comparison-priv.h: Update copyright for 2019
	* src/abg-comparison.cc: Update copyright for 2019
	* src/abg-config.cc: Update copyright for 2019
	* src/abg-corpus-priv.h: Update copyright for 2019
	* src/abg-corpus.cc: Update copyright for 2019
	* src/abg-default-reporter.cc: Update copyright for 2019
	* src/abg-diff-utils.cc: Update copyright for 2019
	* src/abg-dwarf-reader.cc: Update copyright for 2019
	* src/abg-hash.cc: Update copyright for 2019
	* src/abg-ini.cc: Update copyright for 2019
	* src/abg-internal.h: Update copyright for 2019
	* src/abg-ir-priv.h: Update copyright for 2019
	* src/abg-ir.cc: Update copyright for 2019
	* src/abg-leaf-reporter.cc: Update copyright for 2019
	* src/abg-libxml-utils.cc: Update copyright for 2019
	* src/abg-libzip-utils.cc: Update copyright for 2019
	* src/abg-reader.cc: Update copyright for 2019
	* src/abg-reporter-priv.cc: Update copyright for 2019
	* src/abg-reporter-priv.h: Update copyright for 2019
	* src/abg-sptr-utils.cc: Update copyright for 2019
	* src/abg-suppression-priv.h: Update copyright for 2019
	* src/abg-suppression.cc: Update copyright for 2019
	* src/abg-tools-utils.cc: Update copyright for 2019
	* src/abg-traverse.cc: Update copyright for 2019
	* src/abg-viz-common.cc: Update copyright for 2019
	* src/abg-viz-dot.cc: Update copyright for 2019
	* src/abg-viz-svg.cc: Update copyright for 2019
	* src/abg-workers.cc: Update copyright for 2019
	* src/abg-writer.cc: Update copyright for 2019
	* tests/print-diff-tree.cc: Update copyright for 2019
	* tests/test-abicompat.cc: Update copyright for 2019
	* tests/test-abidiff-exit.cc: Update copyright for 2019
	* tests/test-abidiff.cc: Update copyright for 2019
	* tests/test-alt-dwarf-file.cc: Update copyright for 2019
	* tests/test-core-diff.cc: Update copyright for 2019
	* tests/test-diff-dwarf-abixml.cc: Update copyright for 2019
	* tests/test-diff-dwarf.cc: Update copyright for 2019
	* tests/test-diff-filter.cc: Update copyright for 2019
	* tests/test-diff-pkg.cc: Update copyright for 2019
	* tests/test-diff-suppr.cc: Update copyright for 2019
	* tests/test-diff2.cc: Update copyright for 2019
	* tests/test-ini.cc: Update copyright for 2019
	* tests/test-ir-walker.cc: Update copyright for 2019
	* tests/test-lookup-syms.cc: Update copyright for 2019
	* tests/test-read-dwarf.cc: Update copyright for 2019
	* tests/test-read-write.cc: Update copyright for 2019
	* tests/test-types-stability.cc: Update copyright for 2019
	* tests/test-utils.cc: Update copyright for 2019
	* tests/test-utils.h: Update copyright for 2019
	* tests/test-write-read-archive.cc: Update copyright for 2019
	* tools/abiar.cc: Update copyright for 2019
	* tools/abicompat.cc: Update copyright for 2019
	* tools/abidiff.cc: Update copyright for 2019
	* tools/abidw.cc: Update copyright for 2019
	* tools/abilint.cc: Update copyright for 2019
	* tools/abipkgdiff.cc: Update copyright for 2019
	* tools/abisym.cc: Update copyright for 2019
	* tools/binilint.cc: Update copyright for 2019
	* tools/kmidiff.cc: Update copyright for 2019
	* update-copyright.sh: Update new year to 2019

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-01-07 14:54:47 +01:00
Dodji Seketeli
3c0701d59d Support having several debuginfo search dirs for a binary
There are use cases where the split debuginfo file of a given binary
is under a given root directory and that the split debuginfo file
itself depends on an alternate debuginfo file that is under another
unrelated root directory.

In that case, the dwarf reader must be able to look for the debuginfo
files under several unrelated root directories.  The tools abidiff and
abidw must thus support having several occurences of the option
--debug-info-dir1 (or --debug-info-dir2) meaning that the debuginfo
files for the binary must be looked for under several root
directories.

This is what this patch does.

	* doc/manuals/abidiff.rst: Adjust doc for the
	--debug-info-dir{1,2} that can now be provided several times.
	* include/abg-dwarf-reader.h ({create, reset}_read_context)
	(read_corpus_from_elf): Take a vector of debug info root dirs.
	* include/abg-tools-utils.h (trim_leading_string)
	(find_file_under_dir, make_path_absolute_to_be_freed)
	(convert_char_stars_to_char_star_stars): Declare new functions.
	* src/abg-dwarf-reader.cc (find_alt_debug_info_link): Renamed
	find_alt_debug_info_location into this.
	(find_alt_debug_info_path): Define new static function.
	(find_alt_debug_info): Take a vector of debug info root dirs.  Use
	the new find_alt_debug_info_path to look into the debug info root
	dirs for the alt debug info.
	(read_context::debug_info_root_paths_): Define new data member.
	(read_context::read_context): Take a vector of debug info root
	dirs and initialize the new read_context::debug_info_root_paths_.
	(read_context::{initialize, create_default_dwfl}): Take a vector
	of debug info root dirs and adjust.
	(read_context::{add_debug_info_root_paths,
	add_debug_info_root_path, find_alt_debug_info}): Define new member
	functions.
	(read_context::load_debug_info): Look into the debug info roots
	for split debug info files.
	(create_read_context, read_corpus_from_elf): Take a vector of
	debug info root dirs and adjust.
	(has_alt_debug_info): Adjust.
	* src/abg-tools-utils.cc (trim_leading_string)
	(make_path_absolute_to_be_freed, find_file_under_dir)
	(convert_char_stars_to_char_star_stars): Define new functions.
	(entry_of_file_with_name): Define new static function.
	(build_corpus_group_from_kernel_dist_under): Adjust.
	* tests/print-diff-tree.cc (main): Adjust.
	* tests/test-diff-dwarf.cc (main): Adjust.
	* tests/test-ir-walker.cc (main): Adjust.
	* tests/test-read-dwarf.cc (main): Adjust.
	* tools/abicompat.cc (main): Adjust.
	* tools/abidiff.cc (options::di_root_paths{1,2}): Changed
	di_root_path{1,2} into this, change their types into vectors of
	allocated char*.
	(options::prepared_di_root_paths{1,2}): Define new data members.
	(options::~options): Define new destructor.
	(parse_command_line): Adjust.
	(prepare_di_root_paths): Define new static function.
	(handle_error): Remove arguments input_file_name,
	debug_info_dir{1,2}.  Now just take an instance of options
	instead.  Adjust.
	(main): Adjust.
	* tools/abidw.cc (options::dir_root_paths): Renamed dir_root_path
	into this and make it be a vector of allocated char*.
	(options::prepared_di_root_paths): Define new data member.
	(options::~options): Free the allocated char* in
	options::dir_root_paths.
	(parse_command_line): Support several --debug-info-dir.
	(load_corpus_and_write_abixml): Adjust.
	(prepare_di_root_paths): Define static function.
	(main): Adjust.
	* tools/abilint.cc (main): Adjust.
	* tools/abipkgdiff.cc (compare): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-11-08 09:03:32 +01:00
Dodji Seketeli
18e4697e05 Better support array with unknown upper bound
It can happen that arrays are described in DWARF with an unknown upper
bound.  In those cases, if the array is the type of a global variable,
the ELF object corresponding to that global variable should have a
size.  It's that ELF object size that should be taken into account
when comparing versions of that global variable and its type.

This patch fixes issues in the detection and representation of array
subranges with unknown size so that we behave like presented above.

	* include/abg-comparison.h
	(BENIGN_INFINITE_ARRAY_CHANGE_CATEGORY): A new enumerator in the
	diff_category enum.
	(EVERYTHING_CATEGORY): Adjust.
	* src/abg-comparison.cc (get_default_harmless_categories_bitmap):
	Adjust.
	(operator<<(ostream& o, diff_category)): Likewise.
	* include/abg-ir.h (array_type_def::subrange_type::is_infinite):
	Declare new member function.
	* src/abg-ir.cc (array_type_def::subrange_type::priv::infinite_):
	New data member.
	(array_type_def::subrange_type::priv::priv): Initialize it.
	(array_type_def::subrange_type::get_length): Better support
	unknown sized subrange.
	(array_type_def::subrange_type::is_infinite): Define new member
	function.
	* src/abg-comp-filter.cc (has_benign_infinite_array_change):
	Define new static function.
	(categorize_harmless_diff_node): Use the new
	has_benign_infinite_array_change above.
	* src/abg-dwarf-reader.cc (build_subrange_type): Better recognize a
	subrange type with unknown upper bound.  Represent that with the
	new array_type_def::subrange_type::is_infinite member property.
	* src/abg-reader.cc (build_subrange_type): Likewise.
	* tests/data/test-abidiff/test-PR18166-libtirpc.so.abi: Adjust.
	* tests/data/test-annotate/libtest23.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-annotate/test7.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/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/test19-pr19023-libtcmalloc_and_profiler.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>
2018-10-16 18:00:22 +02:00
Dodji Seketeli
caa100603e Bug 23708 - categorize void* to pointer change as harmless
Changing a void* pointer into another pointer of the same size is a
change that is harmless in terms of data layout.

This commit thus categorizes such a change as harmless.

	* include/abg-comparison.h (VOID_PTR_TO_PTR_CHANGE_CATEGORY): New
	enumerator in the diff_category enum.  Also, adjust the
	EVERYTHING_CATEGORY enumerator.
	* include/abg-fwd.h (is_void_pointer_type): Declare new function.
	* src/abg-comp-filter.cc (has_void_ptr_to_ptr_change): Define new
	static function and ...
	(categorize_harmless_diff_node): ... use it here.
	* src/abg-comparison.cc (get_default_harmless_categories_bitmap):
	Add the new abigail::comparison::VOID_PTR_TO_PTR_CHANGE_CATEGORY
	category in here.
	(operator<<(ostream& o, diff_category c)): Add support for the new
	VOID_PTR_TO_PTR_CHANGE_CATEGORY.
	* src/abg-ir.cc	(is_void_pointer_type): Define new function.
	* tests/data/Makefile.am: Add the new test material below to source distribution.
	* tests/data/test-diff-filter/test47-filter-void-ptr-change-report-0.txt:
	New test reference output.
	* tests/data/test-diff-filter/test47-filter-void-ptr-change-v{0,1}.c:
	Source code of the new binary test input below.
	* tests/data/test-diff-filter/test47-filter-void-ptr-change-v{0,1}.o:
	New binary test input.
	* tests/test-diff-filter.cc: Add the test input/output above to
	test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-10-03 11:42:47 +02:00
Dodji Seketeli
a16e97596b Categorize CV qualifier changes on fn return types as harmless
This partially fixes PR23700.

A change in the CV qualifiers of a function return value type should
be categorized as harmless.  And this is what this patch does.

	* include/abg-comparison.h (FN_RETURN_TYPE_CV_CHANGE_CATEGORY):
	New enumerator for diff_category.
	(EVERYTHING_CATEGORY): Update.
	* src/abg-comp-filter.cc (type_diff_has_cv_qual_change_only):
	Factorize this function out of ...
	(has_fn_parm_type_cv_qual_change): ... this one.
	(has_fn_return_type_cv_qual_change): Define new static function.
	(categorize_harmless_diff_node): Use the new
	has_fn_return_type_cv_qual_change.
	* src/abg-comparison.cc (get_default_harmless_categories_bitmap):
	Adjust to add the new FN_RETURN_TYPE_CV_CHANGE_CATEGORY category.
	(operator<<(ostream& o, diff_category c)): Support the new
	FN_RETURN_TYPE_CV_CHANGE_CATEGORY.
	* tests/data/Makefile.am: Add the new test material below to
	source distribution.
	* tests/data/test-diff-filter/test46-fn-return-qual-change-report-0.txt:
	New reference output for the new input test.
	* tests/data/test-diff-filter/test46-fn-return-qual-change-v{0,1}.c:
	New source code for the new binary test input.
	* tests/data/test-diff-filter/test46-fn-return-qual-change-v{0,1}.o:
	New binary test input files.
	* tests/test-diff-filter.cc: Add the new test input above to test
	harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-10-02 14:02:22 +02:00
Dodji Seketeli
60daf958ae Fix propagation of private type suppression category
This is a partial fix of PR23700.

Conceptually, there are two kinds of type suppression specifications:

1/ a generic user-provided suppression specification that is meant to
suppress changes on types specified by the user

2/ a private type suppression specification that is automatically
generated from the path to public header files provided by the user.

Technically, one difference between 1 and 2 lays in the way we
propagate categories of changes matched by those suppression
specifications.

If a class type change of category SUPPRESSED_CATEGORY is referenced
in a typedef change, then the typedef change is also considered to be
of category SUPPRESSED_CATEGORY.  In other words, the
SUPPRESSED_CATEGORY category is propagated to the typedef change.
That means that if a change to a class type is suppressed, a (changed)
typedef to that class is considered to be suppressed too.

But then that is not true if the class type was changed because it's
private.  In that, a typedef to that class can be *public*, because
the said typedef is defined in a public header.  In that case the
typedef change should *NOT* be considered suppressed just because the
class type change was suppressed.

The problem we have here is that we don't make any difference between
1/ and 2/.  So we need to introduce different propagation rules for 1/
and 2/.

So this patch introduces a new PRIVATE_TYPE_CATEGORY category for
types suppression specification that are automatically generated for
private types.  That new category has its own propagation rule which
is basically "no propagation"; every type must be matched by the
private type suppression specification to be considered as private.

	* include/abg-comp-filter.h (has_harmful_name_change): Declare new
	function overloads.
	* include/abg-comparison.h (PRIVATE_TYPE_CATEGORY): New enumerator
	for diff_category;
	(EVERYTHING_CATEGORY): Adjust this enumerator in diff_category;
	(is_suppressed): Take an output parameter to say if the
	suppression is a private type suppression.
	* include/abg-suppression.h (is_private_type_suppr_spec): Take a
	const reference parameter and add an overload for a shared
	pointer.
	* src/abg-comp-filter.cc (has_harmful_name_change): Define new
	function.
	* src/abg-comparison-priv.h (diff::priv::is_filtered_out): Diffs
	of category PRIVATE_TYPE_CATEGORY are also considered filtered
	out.
	* src/abg-comparison.cc (diff::is_filtered_out): Adjust to account
	for canonical diffs of category PRIVATE_TYPE_CATEGORY.
	(diff::is_suppressed): Add an overload that takes a
	is_private_type output parameter.  Re-write the old overload in
	terms of the new one.
	(operator<<(ostream& o, diff_category c)): Handle
	PRIVATE_TYPE_CATEGORY.
	(category_propagation_visitor::visit_end):  Do not propagate
	PRIVATE_TYPE_CATEGORY here. Do not propagate
	HARMLESS_DECL_NAME_CHANGE_CATEGORY either, when the class does
	have a harmful decl name change.
	(suppression_categorization_visitor::visit_begin): Set the new
	PRIVATE_TYPE_CATEGORY category but do not propagate it.
	(suppression_categorization_visitor::visit_end): Add some
	comments.
	* src/abg-default-reporter.cc (default_reporter::report): Avoid
	reporting typedef underlying types that are in the
	PRIVATE_TYPE_CATEGORY category.
	* src/abg-suppression.cc (type_suppression::suppresses_diff): Do
	not peel typedefs if we are a private type suppression.
	(is_private_type_suppr_spec): Take a const reference.
	* tests/data/Makefile.am: Add the new test material below to
	source distribution.
	* tests/test-diff-suppr.cc: Use new test binary input.
	* tests/data/test-diff-filter/test7-report.txt: Adjust.
	* tests/data/test-diff-suppr/test39-opaque-type-report-0.txt: New
	test reference output.
	* tests/data/test-diff-suppr/test39-opaque-type-v{0,1}.c: Source
	code of new test binary input.
	* tests/data/test-diff-suppr/test39-opaque-type-v{0,1}.o: New test
	binary input.
	* tests/data/test-diff-suppr/test39-public-headers-dir/test39-header-v{0,1}.h:
	Source code of new test binary input.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-10-01 16:14:50 +02:00
Dodji Seketeli
af73844b97 Add option to avoid walking abigail::ir nodes twice
When the ir_traversable_base::traverse() walks the IR graph, it
happens that it can visit a type node that was already visited before.
For instance, it visits the 'struct S' once and later, as part of its
visit of struct S*, it can visit struct S again.

There are use cases where we want the walker to avoid visiting a given
type node again.  This patch adds the option to do so.

Basically the ir_node_visitor class can now be configured to tell the
walker to avoid re-visiting a node.

The test-ir-walker.cc example is amended to avoid re-visiting type nodes
as well.

	* include/abg-ir.h (struct ir_node_visitor): Make this be a class.
	Add a private data member to it, following the 'pimpl' idiom.
	(ir_node_visitor::{allow_visiting_already_visited_type_node,
	mark_type_node_as_visited, forget_visited_type_nodes,
	type_node_has_been_visited}): Declare new member functions.
	* src/abg-ir.cc ({type_base, type_decl, scope_type_decl,
	qualified_type_decl, pointer_type_def, reference_type_def,
	array_type_def, enum_type_decl, typedef_decl, class_or_union,
	class_decl, union_decl}::traverse): Avoid re-visiting the type
	node if the visitor was configured as such.
	(struct ir_node_visitor::priv): Define new struct.
	(ir_node_visitor::{allow_visiting_already_visited_type_node,
	mark_type_node_as_visited, forget_visited_type_nodes,
	type_node_has_been_visited}): Define new member functions.
	* tests/test-ir-walker.cc
	(name_printing_visitor::name_printing_visitor): Avoid visiting a
	type node twice.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-09-03 13:32:06 +02:00
Dodji Seketeli
98f972dc1d Bug 23533 - Accept '=' in ini property values
It appears that it's not possible to write a suppression specification
like the below at the moment:

  [suppress_file]
  label = Libabigail can't handle libgfortran.so (https://sourceware.org/bugzilla/show_bug.cgi?id=23492)
  file_name_regexp = libgfortran\\.so.*

This is because the ini parser won't accept the '=' character in the
URL as a valid character for ini property values.

So the entire [suppress_file] section is ignored by the suppression
specification engine.

This patch fixes that by making the equal character valid in property
values.

	* src/abg-ini.cc (char_is_delimiter): Take a new include_equal
	flag to control is the equal character should be considered as a
	delimiter or not.
	(char_is_property_value_char): Accept the equal character as a
	valid property value character.
	* tests/Makefile.am: Build a new runtestini test from the new
	tests/test-ini.cc source file.
	* tests/data/Makefile.am: Add the two new test inputs below to
	source distribution.
	* tests/data/test-ini/test01-equal-in-property-string.{abignore,
	abignore.expected}: New test inputs.
	* tests/test-ini.cc: New test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-08-30 10:54:33 +02:00
Dodji Seketeli
a6e6532352 Make test-ir-walker work on ELF binaries directly
The tests/test-ir-walker.cc example was working on abixml files
resulting from abidw.  This commit changes that to make it work on
ELF input files directly.  The commit also adds some comments to make
it easier to understand the concepts.

	* test-ir-walker.cc (main): Load an ABI corpus from an elf file
	and walk its translation units.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-08-06 10:28:06 +02:00
Dodji Seketeli
42fe5aa2c8 Properly add test materials for test-diff-suppr/test38-char-class-in-ini*
While adding test materials for
test-diff-suppr/test38-char-class-in-ini* to source distribution, I
got the paths wrong.  Fixing thus.

	* tests/data/Makefile.am: Add proper path for
	test-diff-suppr/test38-char-class-in-ini*.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-07-13 10:13:09 +02:00
Dodji Seketeli
1478d9cc1c Allow square brackets in ini property values
Sometimes, one wants to be able to write suppression specifications
like:

    [suppress_function]
     filename_regexp = ^test38-char-class-in-ini-v[[:digit:]].*
     symbol_name_regexp = bar
     change_kind = added-function

without having to escape the square brackets in the regexp.  Normally,
one has to escape the '[' and the ']' because these characters are
used to define ini section names (e.g, [suppress_function]).

This patch allows the presence of the square bracket characters in a
property value, making the suppression specification above valid.

	* src/abg-ini.cc (char_is_delimiter): Possibly disallow square
	bracket characters into the set of delimiters.
	* tests/data/test-diff-suppr/test38-char-class-in-ini-report-0.txt:
	New reference output.
	* tests/data/test-diff-suppr/test38-char-class-in-ini-v{0,1}.c:
	Source code new test binaries.
	* tests/data/test-diff-suppr/test38-char-class-in-ini-v{0,1}.o:
	New test binaries.
	* tests/data/test-diff-suppr/test38-char-class-in-ini.abignore:
	New test abi suppression file.
	* tests/data/Makefile.am: Add the new test materials above to
	source distribution.
	* tests/test-diff-suppr.cc: Add the test materials above to the
	set of tests to run.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-07-12 13:47:08 +02:00
Dodji Seketeli
df72389155 Fix race between runtestdefaultsupprs{py3.sh,.py}
runtestdefaultsupprspy3.sh just runs runtestdefaultsupprs.py using
python3.  So when both run in parallel, it can happen that they step
on their toes as they emit content into some files.

This patch commits makes it so that runtestdefaultsupprspy3.sh is
executed only if we are in the python3 mode, otherwise we just run
runtestdefaultsupprs.py, fixing the occasional failure that we see on
either runtestdefaultsupprs.py or runtestdefaultsupprspy3.sh.

	* tests/Makefile.am: Run runtestdefaultsupprspy3.sh if we are in
	python3 mode otherwise run runtestdefaultsupprs.py.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-07-10 14:08:19 +02:00