Commit Graph

2154 Commits

Author SHA1 Message Date
Matthias Maennich
cd5fdfe1b6 dwarf-reader: Remove unused code
Cleanup code that is never used to reduce overall compiled code and
complexity. Some are leftovers from prior refactorings, some are unused
overloads where the more suitable overload is still left.

	* src/abg-dwarf-reader.cc
	(lookup_public_variable_symbol_from_elf): Delete.
	(read_context::bss_section_): Delete.
	(read_context::text_section_): Delete.
	(read_context::rodata_section_): Delete.
	(read_context::data_section_): Delete.
	(read_context::data1_section_): Delete.
	(read_context::initialize): Remove initializations of deleted members.
	(read_context::options): Delete.
	(read_context::bss_section): Delete.
	(read_context::text_section): Delete.
	(read_context::rodata_section): Delete.
	(read_context::data_section): Delete.
	(read_context::data1_section): Delete.
	(read_context::get_elf_file_type): Delete.
	(read_context::lookup_symbol_from_elf): Delete.
	(read_context::lookup_public_variable_symbol_from_elf): Delete.
	(read_context::fun_addr_sym_map_sptr): Delete.
	(read_context::fun_addr_sym_map): Delete.
	(read_context::get_data_section_for_variable_address): Delete.
	(read_context::suppression_matches_function_sym_name): Delete.
	(read_context::suppression_matches_function_name): Delete.
	(read_context::suppression_matches_type_name): Delete.

Signed-off-by: Matthias Maennich <maennich@google.com>
2020-06-11 10:02:58 +02:00
Dodji Seketeli
7da00ff4b7 abigail.m4: Fix copyright notice
I wrote this file and added it to the repository in the commit:

    e4fefbdb Allow autoconf-based clients to detect the library

But then I added the wrong copyright notice back then.  Fixed thus.

	* abigail.m4: Mention Red Hat in the copyright and myself as author.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-29 18:11:10 +02:00
Matthias Maennich
72eb3fe482 tests: Add kernel symtab test suite
Add (Catch based) test suite to test kernel symbol table (ksymtab)
reading through the result persisted in abigail::corpus.

The test cases are created through simple kernel module C source files
targeting the desired properties ((gpl) exported / local functions /
variables). The kernel binaries are built without debug information to
keep them reasonably small and reproducible. That is just enough
sufficient to analyze ksymtabs. The Makefile that comes with them
recreates the test cases from the sources, given a kernel source tree
with the appropriate version, e.g.

   make KDIR=/path/to/4.14

This covers ksymtab reading and ensuring we detect the kernel binary
correctly. The kernel versions are selected based on features introduced
into the Linux kernel that affect the ksymtab representation.

 - Linux v4.14 - reasonably old kernel to start with (actually v4.14.180)
 - Linux v4.19 - first version having position relative relocations
		 (PREL) in ksymtab entries on some platforms
		 (actually v4.19.123)
 - Linux v5.4  - first version having symbol namespaces (actually v5.4.41)
 - Linux v5.6  - latest released stable kernel as of writing (actually v5.6.13)

	* tests/data/Makefile.am: add new test data for runtestsymtab
	* tests/data/test-symtab/kernel-4.14/Makefile: New test case makefile.
	* tests/data/test-symtab/kernel-4.14/empty.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_function.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_variable_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-4.14/empty.ko: New test data.
	* tests/data/test-symtab/kernel-4.14/one_of_each.ko: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_function.ko: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_function_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_variable.ko: Likewise.
	* tests/data/test-symtab/kernel-4.14/single_variable_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/Makefile: New test case makefile.
	* tests/data/test-symtab/kernel-4.19/empty.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_function.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_variable_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-4.19/empty.ko: New test data.
	* tests/data/test-symtab/kernel-4.19/one_of_each.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_function.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_function_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_variable.ko: Likewise.
	* tests/data/test-symtab/kernel-4.19/single_variable_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/Makefile: New test case makefile.
	* tests/data/test-symtab/kernel-5.4/empty.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_function.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_variable_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-5.4/empty.ko: New test data.
	* tests/data/test-symtab/kernel-5.4/one_of_each.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_function.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_function_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_variable.ko: Likewise.
	* tests/data/test-symtab/kernel-5.4/single_variable_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/Makefile: New test case makefile.
	* tests/data/test-symtab/kernel-5.6/empty.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_function.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_variable_gpl.c: Likewise.
	* tests/data/test-symtab/kernel-5.6/empty.ko: New test data.
	* tests/data/test-symtab/kernel-5.6/one_of_each.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_function.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_function_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_variable.ko: Likewise.
	* tests/data/test-symtab/kernel-5.6/single_variable_gpl.ko: Likewise.
	* tests/data/test-symtab/kernel/Makefile: New test case source file.
	* tests/data/test-symtab/kernel/empty.c: Likewise.
	* tests/data/test-symtab/kernel/one_of_each.c: Likewise.
	* tests/data/test-symtab/kernel/single_function.c: Likewise.
	* tests/data/test-symtab/kernel/single_function_gpl.c: Likewise.
	* tests/data/test-symtab/kernel/single_variable.c: Likewise.
	* tests/data/test-symtab/kernel/single_variable_gpl.c: Likewise.
	* tests/test-symtab.cc: New test case to test kernel symtabs.

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-27 11:00:51 +02:00
Matthias Maennich
2a79ab78f4 tests: Add symtab test suite
Add (Catch based) test suite to test symbol table reading through the
result persisted in abigail::corpus.

The test cases are created through simple C source files targeting the
desired properties (having an undefined/export function or both). The
Makefile that comes with them recreates the test cases from the sources.

This covers reading sorted_(undefined_)var|fun_symbols as well as the
corresponding symbols maps accessible through the accessors of
abigail::corpus.

	* tests/Makefile.am: add new test runtestsymtab
	* tests/data/Makefile.am: add new test data for runtestsymtab
	* tests/data/test-symtab/Makefile: Add this to build the binaries
	below from their source code.
	* tests/data/test-symtab/basic/empty.c: New test case source.
	* tests/data/test-symtab/basic/link_against_me.c: Likewise.
	* tests/data/test-symtab/basic/no_debug_info.c: Likewise.
	* tests/data/test-symtab/basic/one_function_one_variable.c: Likewise.
	* tests/data/test-symtab/basic/one_function_one_variable_undefined.c: Likewise.
	* tests/data/test-symtab/basic/single_function.c: Likewise.
	* tests/data/test-symtab/basic/single_undefined_function.c: Likewise.
	* tests/data/test-symtab/basic/single_undefined_variable.c: Likewise.
	* tests/data/test-symtab/basic/single_variable.c: Likewise.
	* tests/data/test-symtab/basic/empty.so: New test data, built from
	the Makefile above.
	* tests/data/test-symtab/basic/link_against_me.so: Likewise.
	* tests/data/test-symtab/basic/no_debug_info.so: Likewise.
	* tests/data/test-symtab/basic/one_function_one_variable.so: Likewise.
	* tests/data/test-symtab/basic/one_function_one_variable_undefined.so: Likewise.
	* tests/data/test-symtab/basic/single_function.so: Likewise.
	* tests/data/test-symtab/basic/single_undefined_function.so: Likewise.
	* tests/data/test-symtab/basic/single_undefined_variable.so: Likewise.
	* tests/data/test-symtab/basic/single_variable.so: Likewise.
	* tests/test-symtab.cc: New test driver.

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-27 11:00:51 +02:00
Dodji Seketeli
e8bf5b803c Bug 25989 - type_topo_comp doesn't meet irreflexive requirements
When emitting abixml types inside a given scope are sorted
topologically.  Types that don't have source definition location
information are sorted lexicographically.

There are certain types however that need more careful consideration.

Those are empty-qualified types.  That is, qualified types (like
cv-qualified types) that carry no qualifier.  The patch explains
in-extenso in comments where those types come from.  You can also look
at the comments of the function maybe_strip_qualification for even
more context.

Simply put, an empty qualified type like 'NONE reference type' equals it's
non-qualified variant 'reference type'.

During the topological sorting, we chose to have the empty-qualified
variant "come before" (i.e, be "less than") the non-qualified variant.
This is alright.

The bug however is that we failed to handle the case were we are
looking at two empty-qualified types that are equal.  In that case, of
course, they are meant to be topologically equivalent.

Fixed thus.

	* src/abg-ir.cc (type_topo_comp::operator()): In the comparison
	operator consider two equivalent empty-qualified types as being
	topologically equivalent.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-19 12:11:27 +02:00
Dodji Seketeli
5eb4d7627a Bug 25661 - Support data member replacement by anonymous data member
We ought to detect when a data member is replaced by an anonymous data
member in a way that doesn't change the ABI in an incompatible way,
especially when that change is non equivocal.

For instance, consider this ABI-visible struct:

    struct S
    {
      int a;
    };

Now, consider that it's changed into:

    struct S
    {
      union
      {
	int a;
	char b;
      };
    };

Stricto sensu, the bit-layout of struct S doesn't change and so that
change isn't ABI-incompatible.

The current version of libabigail however flags that change as a
/potential/ issue and asks the user for further review.  It appears
that this class of changes is frequent enough to be annoying,
especially in semi-automatic ABI compliance checking setups where we
want the least possible "false positives".

This patch detects that kind of change patterns where a data member is
replaced by an anonymous data member in a benign way, in terms of ABI.

So now let's look at a more complicated example where an ABI-visible
type looks like:

struct S
{
  int a;
  int b;
  int c;
};

Now suppose that type was changed into:

struct S
{
  union
  {
    int tag[3];
    struct
    {
      int a;
      int b;
      int c;
    };
  };
};

The patch allows abidiff to recognise that kind of pattern, filter out
the detected change and report by default that the two binaries are
ABI compatible.

Here are the output that we'd get:

$ abidiff test-v0.o test-v1.o
Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added function
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

When asked to show the detailed of the filtered out changes, we get:

$ abidiff --harmless test-v0.o test-v1.o
Functions changes summary: 0 Removed, 1 Changed, 0 Added function
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

1 function with some indirect sub-type change:

  [C] 'function void foo(S*)' at test-v1.cc:18:1 has some indirect sub-type changes:
    parameter 1 of type 'S*' has sub-type changes:
      in pointed to type 'struct S' at test-v1.cc:1:1:
        type size hasn't changed
        data members 'S::a', 'S::b', 'S::c' were replaced by anonymous data member:
          'union {int tag[3]; struct {int a; int b; int c;};}'

And using the leaf-node reporter, that would give:

$ abidiff --leaf-changes-only --harmless test-v0.o test-v1.o
Leaf changes summary: 1 artifact changed
Changed leaf types summary: 1 leaf type changed
Removed/Changed/Added functions summary: 0 Removed, 0 Changed, 0 Added function
Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable

'struct S at test-v0.cc:1:1' changed:
  type size hasn't changed
  data members 'S::a', 'S::b', 'S::c' were replaced by anonymous data member:
    'union {int tag[3]; struct {int a; int b; int c;};}'

	* include/abg-comp-filter.h (has_data_member_replaced_by_anon_dm):
	Declare new function.
	* include/abg-comparison.h (changed_var_sptr)
	(changed_var_sptrs_type): Declare new typedefs.
	(HARMLESS_DATA_MEMBER_CHANGE_CATEGORY): Add a new enumerator to
	the diff_category enum.
	(EVERYTHING_CATEGORY): In the diff_category, adjust this
	enumerator to OR the new HARMLESS_DATA_MEMBER_CHANGE_CATEGORY into
	it.
	(SUPPRESSED_CATEGORY, PRIVATE_TYPE_CATEGORY)
	(SIZE_OR_OFFSET_CHANGE_CATEGORY, VIRTUAL_MEMBER_CHANGE_CATEGORY)
	(CLASS_DECL_ONLY_DEF_CHANGE_CATEGORY)
	(FN_PARM_TYPE_TOP_CV_CHANGE_CATEGORY)
	(FN_RETURN_TYPE_CV_CHANGE_CATEGORY, VAR_TYPE_CV_CHANGE_CATEGORY)
	(VOID_PTR_TO_PTR_CHANGE_CATEGORY)
	(BENIGN_INFINITE_ARRAY_CHANGE_CATEGORY): Adjust the value of these
	enumerators of the diff_category enum.
	(class_or_union_diff::{data_members_replaced_by_adms,
	ordered_data_members_replaced_by_adms}): Declare new member
	functions.
	* include/abg-fwd.h (var_decl_wptr): Declare new typedef.
	(get_next_data_member, get_first_non_anonymous_data_member)
	(find_data_member_from_anonymous_data_member)
	(get_absolute_data_member_offset): Declare new functions.
	* include/abg-ir.h (struct anonymous_dm_hash): Declare new type.
	(anonymous_data_member_sptr_set_type): Declare new typedef.
	(class decl_base): Befriend class class_or_union.
	(class dm_context_rel): Pimpl-ify this class.
	(dm_context_rel::{g,s}et_anonymous_data_member_types): Declare new
	member functions.
	(var_decl::get_anon_dm_reliable_name): Declare new member
	function.
	(class var_decl): Make get_absolute_data_member_offset,
	get_absolute_data_member_offset be friends of this.
	(class_or_union::maybe_fixup_members_of_anon_data_member): Declare
	new protected member function.
	* src/abg-comp-filter.cc (has_data_member_replaced_by_anon_dm):
	Define new function.
	(categorize_harmless_diff_node): Use the above.
	* src/abg-comparison-priv.h
	(class_or_union_diff::priv::{dms_replaced_by_adms_,
	changed_var_sptrs_type dms_replaced_by_adms_ordered_}): Add new
	data members.
	(data_member_comp::compare_data_members): Factorize this out of ...
	(data_member_comp::operator()(decl_base_sptr&, decl_base_sptr&)):
	... this.
	(data_member_comp::operator()(changed_var_sptr&,
	changed_var_sptr&)): Add new member function.
	(sort_changed_data_members): Declare ...
	* src/abg-comparison.cc (sort_changed_data_members): ... new
	function.
	(get_default_harmless_categories_bitmap): Adjust to take the new
	abigail::comparison::HARMLESS_DATA_MEMBER_CHANGE_CATEGORY into
	account.
	(operator<<(ostream& o, diff_category c)): Likewise.
	(class_or_union_diff::ensure_lookup_tables_populated): Handle
	Handle the insertion of anonymous data members to replace existing
	data members.
	(class_or_union_diff::{data_members_replaced_by_adms,
	ordered_data_members_replaced_by_adms}): Define new accessors.
	(suppression_categorization_visitor::visit_end): Propagate the
	SUPPRESSION_CATEGORIZATION_VISITOR from changes to the type of the
	data member if the data member doesn't have real local changes.
	* src/abg-default-reporter.cc (default_reporter::report): Report
	about anonymous data members that replace data members.
	* src/abg-ir.cc (struct dm_context_rel::priv): Define new data
	structure.
	(dm_context_rel::{dm_context_rel, get_is_laid_out,
	set_is_laid_out, get_offset_in_bits, set_offset_in_bits,
	operator==, operator!=, get_anonymous_data_member,
	set_anonymous_data_member}): Define the member functions here as
	they are not inline anymore.
	(class_or_union::maybe_fixup_members_of_anon_data_member): Define
	new member function.
	(class_or_union::add_data_member): Use it.
	(get_first_non_anonymous_data_member, get_next_data_member)
	(get_absolute_data_member_offset)
	(find_data_member_from_anonymous_data_member): Define new
	functions.
	* src/abg-reporter-priv.h
	(maybe_report_data_members_replaced_by_anon_dm): Declare ...
	* src/abg-reporter-priv.cc
	(maybe_report_data_members_replaced_by_anon_dm): ... new function.
	* src/abg-leaf-reporter.cc (leaf_reporter::report): Report data
	members replaced by anonymous data members.
	* tests/data/test-diff-filter/test-PR25661-[1-6]-report-[1-4].txt: New
	test reference outputs.
	* tests/data/test-diff-filter/test-PR25661-[1-6]-v{0,1}.c: Test
	source code files.
	* tests/data/test-diff-filter/test-PR25661-[1-6]-v{0,1}.o: Test
	binary input files.
	* tests/data/Makefile.am: Add the new test files above to source
	distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the binary test
	inputs above to this test harness.
	* tests/data/test-diff-dwarf/test45-anon-dm-change-report-0.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 13:42:50 +02:00
Dodji Seketeli
88fcbfeced dwarf-reader: support several anonymous data members in a given class
At the moment, if a class has more than one anonymous data member, we
are just keeping the first one and dropping the others.

This patch fixes that.

Now that there is the possibility of having several anonymous data
members in a given class we need to be able to name them correctly, to
tell them apart.  That means we cannot use the name returned by
var_decl::get_name() as that name is empty for an anonymous data
member.  This patch thus introduces a new method
var_decl::get_anon_dm_reliable_name() which returns a name that is
reliable (non-empty) even when the var_decl designates an anonymous
data member.  Note that there are many situations where we still need
to have var_decl::get_name() behave like it used to, so we can't make
it invariably return what var_decl::get_anon_dm_reliable_name()
returns today.

	* include/abg-ir.h (class_or_union::find_anonymous_data_member):
	Declare a new member function.
	(class_or_union::find_data_member): Declare a new overload.
	(var_decl::get_anon_dm_reliable_name): Declare new member
	function.
	* src/abg-ir.cc (var_decl::get_pretty_representation): Make this
	work on a var_decl is going to be used to represent an anonymous
	data member even before the var_decl has been added to its finale
	scope.  This is useful to make class_or_union::find_data_member
	work on a var_decl that is to be used as an anonymous data member.
	(var_decl::get_anon_dm_reliable_name): Define new member function.
	(class_or_union::find_data_member): In the existing overload that
	takes a string, look for the named data member inside the
	anonymous data members.  Define a new overload that takes a
	var_decl_sptr, to look for anonymous data members.
	(class_or_union::find_anonymous_data_member): Define a new member
	function.
	(lookup_data_member): Use the existing
	class_or_union::find_data_member.
	* src/abg-reader.cc: (build_class_decl): Use the full anonymous
	variable for lookup, rather than its name which is empty and will
	thus give false positives.
	* src/abg-dwarf-reader.cc (add_or_update_class_type): Likewise.
	* src/abg-comparison.cc
	(class_or_union_diff::ensure_lookup_tables_populated): Name
	anonymous data members properly - as opposed to wrongly using
	their empty name.
	* src/abg-reporter-priv.cc (represent): In the overload for
	var_diff_sptr, make sure that changes to the /type/ of a variable
	declaration are always reported.
	* tests/data/test-abidiff-exit/test-member-size-report0.txt:
	Adjust as we now emit more detailed changes about anonymous data
	members.
	* tests/data/test-abidiff-exit/test-member-size-report1.txt:
	Likewise.
	* tests/data/test-annotate/test-anonymous-members-0.o.abi: Adjust
	to reflect the fact that a class can now have several anonymous
	data members.
	* tests/data/test-diff-dwarf-abixml/PR25409-librte_bus_dpaa.so.20.0.abi:
	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/test35-pr18754-no-added-syms-report-0.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 13:42:50 +02:00
Dodji Seketeli
48f26ddc00 {default,leaf}-reporter: group data members changes reports together
There are two kinds of data member changes:

  1/ changes to the type or offset of a given data member
     basically, in this kind of change, the name of the data member
     remained the same.

  2/ changes where the data member (at a given offset) was replaced by
     something else completely.

Today, the comparison engine recognizes these two kinds of changes and
records them in two different data structures.  This is useful because
it allows for a finer grain analysis.

But when we report these changes, today, we report them separately and
sometimes that doesn't make sense.  For instance, because there is no
change of the 1/ kind, the reporter would say "no data member
changes", and yet go ahead and emit data member changes of the 2/ kind.

This patch groups the reporting of the two kinds of changes so that
when it says "no data member changes", it means there was no data
member changes at all.

	* include/abg-comparison.h
	(class_or_union_diff::{sorted_changed_data_members,
	count_filtered_changed_data_members,
	sorted_subtype_changed_data_members,
	count_filtered_subtype_changed_data_members}): Declare ...
	* src/abg-comparison.cc
	(class_or_union_diff::{sorted_changed_data_members,
	count_filtered_changed_data_members,
	sorted_subtype_changed_data_members,
	count_filtered_subtype_changed_data_members}): ... accessors for
	existing private data members.
	* src/abg-default-reporter.cc (default_reporter::report): In the
	class_or_union_diff& overload, group the reporting of the changes
	to data member sub-types with the replacement of data members.
	These are just data member changes after all.  Use the newly
	declared accessors for better measure.
	* src/abg-leaf-reporter.cc (leaf_reporter::report): Likewise.
	* tests/data/test-diff-dwarf/test45-anon-dm-change-report-0.txt: Adjust.
	* src/abg-leaf-reporter.cc (leaf_reporter::report): Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 13:42:50 +02:00
Dodji Seketeli
84f3740b53 Add -g back to ABIGAIL_DEVEL
I forgot to set the -g option in C{XX}FLAGS when applying the patch
https://sourceware.org/git/?p=libabigail.git;a=commit;h=d02de5a7846d7f44621c1e100e60f36f5a0c051e.
Oops.

Fixed thus.

	* configure.ac: Don't forget to set -g when ABIGAIL_DEVEL is set.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 13:40:42 +02:00
Giuliano Procida
cb1c49e126 clang-format: set continuation indentation to 2
This is a further tweak to the clang-format rules, bringing them
(on average) closer to the existing corpus of code.

The existing code mostly uses an indentaton of 2 spaces, rather than
4, for expressions broken across lines. There are exceptions such as
conditional expressions that are initialisers but clang-format's
indentation may be preferable to emacs' zero indentation here.

	* .clang-format: Set ContinuationIndentWidth to 2.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-18 10:48:09 +02:00
Matthias Maennich
d02de5a784 configure: add more diagnostic options when ABIGAIL_DEVEL is set
When exporting ABIGAIL_DEVEL=1, add more flags to ABIGAIL_DEVEL that are
suitable for development to find issues during edit/compile/test time.

The subsequent changes to source and test code are needed to make the
code compile with ABIGAIL_DEVEL=yes.

Note, unless bug #25989 is addressed, runtestannotate is failing.
See https://sourceware.org/bugzilla/show_bug.cgi?id=25989 for details.

	* configure.ac: add -D_FORTIFY_SOURCE=2 and -D_GLIBCXX_DEBUG
	compilation defines if ABIGAIL_DEVEL is set.  Note that with GCC 4.8.5,
	-D_FORTIFY_SOURCE=2 requires options to be set.  So I am setting
	the optimization level to -Og.
	* src/abg-dwarf-reader.cc (read_context::{compute_canonical_die,
	get_or_compute_canonical_die, associate_die_to_decl,
	set_canonical_die_offset, schedule_type_for_late_canonicalization,
	compare_dies}, get_scope_for_die, add_or_update_union_type)
	(read_debug_info_into_corpus, build_ir_node_from_die): Initialize
	the 'source' variable.
	* tests/test-diff-filter.cc (main): Check the return value of the
	system function.
	* tests/test-diff-pkg.cc (main): Likewise.
	* tests/test-read-write.cc (main): Likewise.

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-18 10:39:36 +02:00
Matthias Maennich
6c23841d98 configure: add ABIGAIL_DEBUG options
When exporting ABIGAIL_DEBUG=1, the binaries compiled are especially
suitable for debugging. The CFLAGS and CXXFLAGS that are added reduce
optimization to a reasonable amount and increase debug information levels.

	* configure.ac: add ABIGAIL_DEBUG environment variable for
	improved debugging capabilities

Signed-off-by: Matthias Maennich <maennich@google.com>
2020-05-18 09:31:38 +02:00
Giuliano Procida
38504ab66c Tidy get_pretty_representation qualified_name.
The virtual function get_pretty_representation exists in many
classes (derived from type_or_decl_base). It takes a qualified_name
argumenta and this is defaulted to true in all but one case which
seems to be an oversight.

This commit changes this for no better reason than consistency.

	* include/abg-ir.h (type_decl::get_pretty_representation)
	Change default for qualified_name parameter to true.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-14 16:34:30 +02:00
Dodji Seketeli
e2341a939c Bug 25986 - Wrong name of function type used in change report
We have introduced type name caching long ago to speed up operations
involving type names.

Then last year, I was looking at some speed optimization in the
xml-writer and I started playing with the caching to quantify the
speed impact that early caching could have on emitting writting out
the abixml, independantly from the potential accuracy issues that
could have.

And somehow I accidentally committed one of those experimental
patches:
https://sourceware.org/git/?p=libabigail.git;a=commit;h=7699dfc921d248fa6d5cbdbeab9d501b17ef3f52.

This commit reverts that bogus patch.  There should be no speed impact
because the writter now de-duplicates types at writting time by
"simply" writting out the canonical types, as opposed to the naive
approach we were using then.

This fixes the bug reported at
https://sourceware.org/bugzilla/show_bug.cgi?id=25986 which shows the
impact of caching the wrong name of the type, which happens when
caching occurs before the type is canonicalized.

	* src/abg-ir.cc (function_type::get_cached_name): Don't cache
	names for non-canonicalized types.
	* tests/data/test-abidiff-exit/test-fun-param-report.txt: Add
	reference output for new test.
	* tests/data/test-abidiff-exit/test-fun-param-v{0,1}.abi: Add new test
	input files.
	* tests/data/test-abidiff-exit/test-fun-param-v{0,1}.c: Add source
	files for the above.
	* tests/data/test-abidiff-exit/test-fun-param-v{0,1}.o: Add
	binaries for the above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-14 09:54:52 +02:00
Mark Wielaard
66e5e36469 Don't iterate before the start of a RandomAccessOutputIterator.
Found with -D_GLIBCXX_DEBUG. You cannot go before the start of an
RandomAccessOutputIterator. Iterator -1 + 1 might seem to work,
but is actually undefined behaviour.

	* include/abg-diff-utils.h (compute_diff): Put brackets around
	p[ux].[xy]() + 1 calculation.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-05-13 13:00:52 +02:00
Giuliano Procida
f7a85ec9d0 doc: Fix sufficient suppression property lists.
At present there are discrepancies between the suppression
specification parsing code and the documented lists of properties (per
suppression type) that are consider sufficient to prevent a
suppression specification being ignored altogether.

This patch updates the documentation to match the code and adjusts
some confusing language in the documentation.

	* doc/manuals/libabigail-concepts.rst: Add missing
	sufficient properties for suppress_file, suppress_function and
	suppress_variable. Use consistent language about what will
	happen when no property in the list in provided.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-13 12:11:11 +02:00
Matthias Maennich
389c1e3385 cxx-compat: add test suite for cxx-compat
This is an empty test to begin with and its sole purpose for now is to
make sure abg-cxx-compat.h can be compiled on its own.

	* tests/Makefile.am: Add new test case runtestcxxcompat.
	* tests/test-cxx-compat.cc: New test source file.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
2020-05-13 11:55:12 +02:00
Matthias Maennich
fef9c6ecec dwarf-reader: read_context: drop some unused accessor methods
Those methods were effectively dead code. Hence only keep the actually
used accessors around:
  const string_elf_symbols_map_sptr& some_sptr();
  string_elf_symbols_map_sptr& some();

	* src/abg-dwarf-reader.cc (read_context::fun_syms_sptr): Delete method.
	(read_context::fun_syms): Likewise.
	(read_context::var_syms_sptr): Likewise.
	(read_context::var_syms): Likewise.
	(read_context::undefined_fun_syms_sptr): Likewise.
	(read_context::undefined_fun_syms): Likewise. Both overloads.
	(read_context::undefined_var_syms_sptr): Likewise.
	(read_context::undefined_var_syms): Likewise. Both overloads.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-13 11:52:12 +02:00
Matthias Maennich
6229bb850f tests/.gitignore: ignore all files starting with runtest*
We only have runtest* executables that we can ignore there with this
prefix. Hence, stop adding each and every test and use an exclusion
pattern instead.

	* tests/.gitignore: gitignore all files named runtest*

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
2020-05-13 11:26:28 +02:00
Matthias Maennich
e5e8cb9543 configure: set -Wno-error-overloaded-virtual for clang builds
When compiling with clang, several locations in the code emit the
warning -Woverloaded-virtual. That warning is not trivial to fix. In order
to allow CXX=clang++ ABIGAIL_DEVEL=1 development, demote the warning to
not be an error when compiling with clang.

	* configure.ac: set -Wno-error-overloaded-virtual for clang++

Signed-off-by: Matthias Maennich <maennich@google.com>
2020-05-13 10:59:14 +02:00
Giuliano Procida
2e8a4b54cd Let std::unordered_map::operator[] insert keys.
This patch replaces some verbose code with one-liners that rely on
std::unordered_map::operator[] to insert a missing key and return a
reference to the default-constructed inserted value.

	* src/abg-reader.cc (read_context::key_type_decl): Rely on
	std::unordered_map::operator[] to create map entries if they
	are missing. (build_elf_symbol_db): Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-13 10:50:25 +02:00
Giuliano Procida
101493793d abg-reader.cc: Remove key_replacement_type_map.
This patch removes this unused function.

	* src/abg-reader.cc (key_replacement_type_map): Drop unused
	function.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-13 10:14:21 +02:00
Giuliano Procida
f32746ca0f Refactor read_parameter_spec_from_string logic.
This function extracts either a string or a regex from the same input.
This patch simplifies the string vs regex conditional logic, in order
to make following patches simpler.

There are no behavioural changes.

	* src/abg-suppression.cc (read_parameter_spec_from_string):
	Use separate string and regex variables to simplify the
	creation of returned parameter specification.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-13 09:49:25 +02:00
Giuliano Procida
249a011913 Use regex::match wrapper instead of regexec.
This patch eliminates all calls to regexec except that by regex::match
itself.

There are no behavioural changes.

	* src/abg-corpus-priv.h: Mechanically substitute use of
	regexec with regex::match wrapper.
	* src/abg-suppression-priv.h: Ditto.
	* src/abg-suppression.cc: Ditto.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-12 18:33:27 +02:00
Giuliano Procida
dc0ac49157 Tidy checks for sufficient suppression properties.
Each suppression specification must have at least one of a documented
per-suppression type list of properties defined if it is to be
considered at all.

At present:

- suppression specifications which fail the check are silently ignored
- in the function suppression case, the check does not trigger an
  early return and risks a later null pointer dereference.

This commit:

- reimplements the checks using arrays and helper function calls
- adds a helper function to determine if a suppression specification
  is going to be ignored due a lack of properties
- makes the parsing functions return failure early if the check fails

Inconsistencies between suppression types (in particular, the
treatment of the "label" property) remain.

The only behavioural change may be to how present but empty properties
are handled. This is an edge case that may be worth revisiting in a
more general fashion in a later commit.

	* src/abg-suppression.cc (check_sufficient_props): New helper
	function to check for sufficient properties in a section.
	(read_type_suppression): Replace conditional logic with call
	to check_sufficient_props.
	(read_function_suppression): Ditto.
	(read_variable_suppression): Ditto.
	(read_file_suppression): Ditto.
	* tests/data/test-diff-suppr/test15-suppr-added-fn-4.suppr:
	Explain why the suppression will be ignored.
	* tests/data/test-diff-suppr/test16-suppr-removed-fn-4.suppr:
	Ditto.
	* tests/data/test-diff-suppr/test17-suppr-added-var-4.suppr:
	Ditto.
	* tests/data/test-diff-suppr/test18-suppr-removed-var-4.suppr:
	Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-12 18:08:33 +02:00
Dodji Seketeli
5d386c08f7 Bug 25977 - runtestabidiffexit regression on EL7
When running runtestabidiffexit I am getting this failure:

$ ./build/tests/runtestabidiffexit
--- /home/dodji/git/libabigail/master/tests/data/test-abidiff-exit/test-leaf-cxx-members-report.txt	2020-04-16 11:19:27.615339665 +0200
+++ /home/dodji/git/libabigail/master/build/tests/output/test-abidiff-exit/test-leaf-cxx-members-report.txt	2020-05-12 16:15:34.316685604 +0200
@@ -1,6 +1,6 @@
-Leaf changes summary: 4 artifacts changed
+Leaf changes summary: 3 artifacts changed (1 filtered out)
 Changed leaf types summary: 1 leaf type changed
-Removed/Changed/Added functions summary: 1 Removed, 1 Changed, 1 Added function
+Removed/Changed/Added functions summary: 1 Removed, 0 Changed (1 filtered out), 1 Added function
 Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable

 1 Removed function:
@@ -13,13 +13,6 @@
   [A] 'method virtual long int ops::added_fn()'    {_ZN3ops8added_fnEv}
     note that this adds a new entry to the vtable of struct ops

-1 function with some sub-type change:
-
-  [C] 'method virtual int ops::changed_fn()' at test-leaf-cxx-members-v1.cc:5:1 has some sub-type changes:
-    return type changed:
-      type name changed from 'int' to 'long int'
-      type size changed from 32 to 64 (in bits)
-
 'struct ops at test-leaf-cxx-members-v0.cc:2:1' changed:
   type size changed from 128 to 192 (in bits)
   1 member function deletion:
@@ -27,10 +20,6 @@
   1 member function insertion:
     'method virtual long int ops::added_fn()' at test-leaf-cxx-members-v1.cc:11:1, virtual at voffset 1/1    {_ZN3ops8added_fnEv}
   there are member function changes:
-    'method virtual int ops::changed_fn()' has some changes:
-      return type changed:
-        type name changed from 'int' to 'long int'
-        type size changed from 32 to 64 (in bits)
   1 data member deletion:
     'int ops::deleted_var', at offset 96 (in bits) at test-leaf-cxx-members-v0.cc:5:1
   1 data member insertion:
$

This is because we wrongly consider the canonical diff node for the
change on the type of function "int ops::changed_fn()" as being
suppressed.  This is because of an old thinko in the suppression
categorization and propagation pass for local types changes to
functions.  Oops.

Fixed thus.

	* abg-comparison.cc:
	(suppression_categorization_visitor::visit_end): Don't suppress
	the entire class of equivalence of a function diff node if that
	function diff node itself was not suppressed.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-12 17:13:09 +02:00
Giuliano Procida
a7ff58e626 Use regex::compile wrapper instead of regcomp.
This patch eliminates all calls to regcomp except that by
regex::compile itself.

	* src/abg-corpus-priv.h: Mechanically substitute use of
	regcomp with regex::compile wrapper.
	* src/abg-suppression-priv.h: Ditto.

There are no behavioural changes.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 18:30:51 +02:00
Giuliano Procida
c72f52c381 Add POSIX regex wrapper functions.
libabigail code uses the POSIX regex library consistently:

    - compile std::string to regex, with the flag REG_EXTENDED
    - store regex using a shared pointer wrapper
    - check match of regex against std::string

All the C string / std::string logic and so on is repeated at every
call site. This patch introduces wrapper functions to take care of
this logic.

There are no behavioural changes.

	* include/abg-regex.h (compile): Declare new function.
	(match): Declare new function.
	* src/abg-regex.cc (compile): Add new function wrapping
	regcomp. (match): Add new function wrapping regexec.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 18:30:44 +02:00
Giuliano Procida
db8e3a0584 abg-suppression.cc: More uniform variable naming.
In abg-suppression.cc most of the read_*_suppression functions
populate and return a single variable "result". Others vary a little
from this, having variables "nil" or "suppr".

This patch makes all the functions use a single variable "result".
This will make the next patches a bit simpler.

There are no behavioural changes.

	* src/abg-suppression.cc (read_type_suppression): Rename "nil"
	variable to "result" and reset it instead of introducing
	"suppr" later on. (read_function_suppression): Rename "nil"
	variable to "result" and reset it instead of introducing
	"result" later on.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 16:04:18 +02:00
Giuliano Procida
44ce7a5755 Escape names used in symbol whitelisting regex.
There is the theoretical possibility that symbols may contain special
regex characters like '.' and '$'. This patch ensures all such
characters in symbol names are escaped before they are added to the
whitelisting regex.

	* include/regex.h (escape): New string reference holder
	class. (operator<<): Declaration of std::ostream,
	regex::escape overload.
	* include/regex.cc (operator<<): New std::ostream,
	regex::escape overload that outputs regex-escaped strings.
	* src/abg-tools-utils.cc
	(gen_suppr_spec_from_kernel_abi_whitelists): Make sure any
	special regex characters in symbol names are escaped.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 15:58:11 +02:00
Giuliano Procida
8b116e14cb Document ^_^ regex in generate_from_strings.
Following review of the change to simplify generation of symbol
whitelist regexes, this commit clarifies the purpose of the ^_^ regex
as one which will not match any string.

	* src/abg-regex.cc (generate_from_strings): Document ^_^
	regex.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 15:31:31 +02:00
Giuliano Procida
1bcfdfd6bd Tidy #includes in a few files.
Following review of a recent change to move regex definitions into
their own files, this commit ensures that #include directives are
separated into categories and sorted alphabetically within the
categories, subject to known ordering constraints (such as "config.h"
first, "abg-internal.h" before visibility directives etc.).

There are no behavioural changes.

	* src/abg-corpus-priv.h: Separate and sort #include
	directives.
	* src/abg-corpus.cc: Ditto.
	* src/abg-regex.cc: Ditto.
	* src/abg-suppression-priv.h: Ditto.
	* src/abg-suppression.cc: Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 15:21:46 +02:00
Giuliano Procida
40423cb54a Hoist some common expressions evaluating offsets.
This is for readability.

	* src/abg-suppression.cc (type_suppression::suppresses_diff):
	Hoist some constant expressions out of loops.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 15:05:29 +02:00
Giuliano Procida
1a3c6ec12a Make set_drops_artifact_from_ir non-const.
Setters should be non-const but set_drops_artifact_from_ir isn't.
This patch fixes this.

This reason this didn't cause a compilation failure is that const
shared_ptr<X> is equivalent to X *const, not const X*.

Note that resolving the apparent const-safety issue will require
std::experimental::propagate_const or similar.

	* include/abg-suppression.h
	(suppression_base::set_drops_artifact_from_ir):
	Drop const qualifier.
	* src/abg-suppression.cc
	(suppression_base::set_drops_artifact_from_ir):
	Drop const qualifier.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 14:36:55 +02:00
Giuliano Procida
e8a2bb439d Eliminate redundant conditional operators.
Code of the form

  bool x = expression ? true : false;

can be written more concisely as

  bool x = expression;

This patch does this. There are no occurences of "? false : true".

	* src/abg-corpus.cc (corpus::priv::build_unreferenced_symbols_tables):
	Eliminate redundant conditional operator.
	* src/abg-dwarf-reader.cc (build_reference_type): Ditto.
	* src/abg-reader.cc (read_static): Ditto.
	(read_is_artificial): Ditto. (build_function_parameter):
	Ditto. (build_function_decl): Ditto.
	(build_qualified_type_decl): Ditto.
	(build_reference_type_def): Ditto.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 14:23:20 +02:00
Giuliano Procida
8282d92304 Remove stray semicolons.
This patch removes various stray semicolons.

	* include/abg-diff-utils.h (display_edit_script): Remove
	redundant semicolon.
	* include/abg-fwd.h (lookup_basic_type): Ditto.
	* src/abg-comparison.cc (mark_diff_as_visited):
	Ditto.	(array_diff::has_local_changes): Ditto.
	(class_diff::ensure_lookup_tables_populated): Ditto.
	* src/abg-corpus.cc
	(corpus::priv::build_unreferenced_symbols_tables): Ditto.
	* src/abg-default-reporter.cc (default_reporter::report):
	Ditto.
	* src/abg-dwarf-reader.cc (finish_member_function_reading):
	Ditto.
	* src/abg-ir.cc (is_compatible_with_class_type): Ditto.
	(enum_type_decl::enumerator::set_name): Ditto.
	* src/abg-reader.cc (read_corpus_from_input): Ditto.
	(build_function_type): Ditto.
	* src/abg-suppression.cc (type_suppression::suppresses_type):
	Ditto.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-11 14:13:20 +02:00
Giuliano Procida
de9682e5f7 Remove excess whitespace.
This patch removes some excess blank lines and a space after the
prefix ++ operator.

	* src/abg-suppression.cc: Eliminate double blank lines.
	(read_parameter_spec_from_string): Eliminate space between
	++ operator and its operand.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-11 14:04:47 +02:00
Matthias Maennich
246ca20049 corpus/writer: sort emitted translation units by path name
By sorting the corpora output, we achieve determinism for the emitted
XML file across multiple runs of abidw.

For that to happen, change the collection of translation units to a
std::set (instead of std::vector), sorted by absolute path name.

Test data needed adjustments, but changes are fully compatible.

	* include/abg-fwd.h: remove translation_units fwd declaration.
	* include/abg-ir.h (struct shared_translation_unit_comparator):
	Define new class.
	(translation_units): Define new typedef.
	* src/abg-corpus.cc (corpus::add): do checked insert into the
	translation_units set (rather than vector::push_back)
	* tests/data/test-annotate/test13-pr18894.so.abi: Adjust test data.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-05 13:09:34 +02:00
Matthias Maennich
0b9560c19b tests: reorder test execution to optimize 'make check' runtime
Reorder the test definition to first start expensive tests and later on
start tests with short runtime. This optimizes the 'make check' runtime
by starting the tests on the critical path.

	* tests/Makefile.am(TESTS): split up in expensive and non
	expensive tests, sort the expensive ones by runime, the cheap
	ones alphabetically

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-04 15:53:45 +02:00
Matthias Maennich
c8b0327e50 test-types-stability: parallelize test case alternatives
Commit a9f5fb4089 ("Add --no-write-default-sizes option.") introduced
a new test variant for test-types-stability that is actually independent
of the original test case in terms of execution. Hence it can be
expressed as a separate test case. So, do that by parametrizing the
test_task struct with a new no_default_sizes flag and schedule a
separate test case in the main loop.

That test runs now ~twice as fast dropping from roughly 20s on my
machine to 10s. That effectively removes it from the critical path of
make check, which is now back to about 15s on my machine with my
configuration.

	* tests/test-types-stability.cc (test_task): add field no_default_sizes
	(test_task::perform) Switch on the new flag to test a different
	behaviour.
	(main): Schedule an additional test case to test with the new flag.

Cc: Mark Wielaard <mark@klomp.org>
Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-04 15:34:42 +02:00
Dodji Seketeli
f014f8c1f0 Fix compilation with g++ 4.8.5 on el7
G++ 4.8.5 doesn't allow a function template specialization to appear
in a namespace that is different from the namespace where the function
template was declared.  Also, in that namespace, the name of the
specialized function template must be non-fully-qualified.

Fixed thus.

	* include/abg-libxml-utils.h (build_sptr<xmlTextReader>): Wrap
	this specialization in the namespace sptr_utils and do away with
	the sptr_utils qualifier.
	* include/abg-regex.h (build_sptr<regex_t>): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-04 13:07:24 +02:00
Giuliano Procida
186cc9ed3a Simplify generation of symbol whitelist regex.
The code to build the symbol whitelist regex uses things like seekp
and tellp to generate regexes like "^foo$|^bar$".

This patch simplifies the code, for further enhancement, resulting in
generated regexes like "^(foo|bar)$".

There should be no change in behaviour, unless whitelisted symbol
names contain special regex characters.

	* include/abg-regex.h (generate_from_strings): Declare new
	function to build a regex from some strings, representing a
	membership test.
	* src/abg-regex.cc (generate_from_strings): Implement new
	function to build a regex from some strings, representing a
	membership test, in a straightfoward fashion.
	* src/abg-tools-utils.cc
	(gen_suppr_spec_from_kernel_abi_whitelists): Replace
	regex-building code with a call to generate_from_strings.
	* tests/test-kmi-whitelist.cc: Update regexes in test.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-04 11:17:49 +02:00
Giuliano Procida
0082ee529f Move libxml bits out of abg-sptr-utils.h.
The header file abg-sptr-utils.h contains generic things relating to
shared pointers. It also contains shared pointer typedefs (in the
sptr_utils namespace) and template specialisations for XML types.

The last of these more naturally belong in abg-libxml-utils.h (and in
the xml namespace). This patch moves them.

There are no behavioural changes.

	* include/abg-sptr-utils.h: Remove reader_sptr and
	xml_char_sptr typedefs, from namespace
	sptr_utils. (build_sptr): Remove corresponding template
	function specialisations for these types.
	* include/abg-libxml-utils.h: Add reader_sptr and
	xml_char_sptr typedefs, to namespace xml. (build_sptr): Add
	corresponding template function specialisations for these
	types.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-05-04 11:17:30 +02:00
Giuliano Procida
ae30e5fa96 Move regex definitions to own files.
As a prelude to adding wrapper and helper functions for regex
functionality, it makes sense to move the existing regex code (the
shared pointer type and its specialised deleter) to their own files.

This patch does this and also moves various entities into a new
namespace, abigail::regex. It removes the file abg-sptr-utils.cc which
only contained regex things.

There are no behavioural changes.

	* include/Makefile.am: Add abg-regex.h.
	* src/Makefile.am: Remove abg-sptr-utils.h, add abg-regex.cc
	* include/abg-sptr-utils.h (regex_t_sptr): Remove this
	typedef, from namespace abigail::sptr_utils.
	(regex_t_deleter): Remove this struct, from namespace
	abigail::sptr_utils. (build_sptr): Remove these template
	specialisations, in duplicate, for regex_t_sptr.
	* include/abg-regex.h: New file, introduces namespace
	abigail::regex. (regex_t_sptr): Add this typedef, to namespace
	abigail::regex. (regex_t_deleter): Add this struct, to
	namespace abigail::regex. (build_sptr): Add these template
	specialisations for regex_t_sptr
	* src/abg-sptr-utils.cc: Remove this file.
	* src/abg-regex.cc: Add new file with contents effectively
	the same as abg-sptr-utils.cc.
	* src/abg-corpus-priv.h: Update regex_t_sptr namespace
	qualification.
	* src/abg-corpus.cc: Ditto.
	* src/abg-suppression-priv.h: Ditto.
	* src/abg-suppression.cc: Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-05-04 11:15:23 +02:00
Mark Wielaard
a9f5fb4089 Add --no-write-default-sizes option.
abidw will write out the exact same size-in-bits address for every
pointer type, reference type, function declaration and function type
even though it is always the same as the translation unit address
size. When giving the --no-write-default-sizes option these aren't
written out anymore. The reader is updated to set the default size
when none is given in the XML description.

Even though size and alignment are handled together in the reader,
default alignment is still set to zero, following commit a05384675

Note that this isn't backward compatible with older libabigail
readers, which will set the size to zero when none is given. So this
option isn't the default.

	* doc/manuals/abidw.rst: Document --no-write-default-sizes.
	* include/abg-writer.h (set_write_default_sizes): New function
	declaration.
	(set_common_options): Call set_write_default_sizes.
	* src/abg-reader.cc (build_function_decl): Get default size.
	(build_pointer_type_def): Likewise.
	(build_reference_type_def): Likewise.
	(build_function_type): Likewise.
	* src/abg-writer.cc (write_context): Add m_write_default_sizes
	bool.
	(get_write_default_sizes): New method.
	(set_write_default_sizes): Likewise.
	(write_size_and_alignment): Add default size and alignment
	parameters.
	(set_write_default_sizes): New function.
	(write_type_decl): Set default size and alignment.
	(write_pointer_type_def): Likewise.
	(write_reference_type_def): Likewise.
	(write_function_decl): Likewise.
	(write_function_type): Likewise.
	(write_class_decl_opening_tag): Likewise.
	(write_union_decl_opening_tag): Likewise.
	* tests/test-types-stability.cc (perform): Also test --abidiff
	with --no-write-default-sizes.
	* tools/abidw.cc (option): Add default_sizes bool.
	(parse_command_line): Parse --no-write-default-sizes.
	(display_usage): Add doc string for --no-write-default-sizes.

Signed-off-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-04-29 11:56:40 +02:00
Mark Wielaard
440fc7f4be Rename read_elf_symbol_binding to read_elf_symbol_visibility.
read_elf_symbol_binding was overloaded so that it could be called to
read either a binding or a visibility attribute. This is slightly
confusing, since another elf_symbol attribute, type, does have its own
read_elf_symbol_type. Rename the read_elf_symbol_binding that reads
the visibility to read_elf_symbol_visibility for claritiy.

    * src/abg-reader.cc (read_elf_symbol_binding): Renamed to...
    (read_elf_symbol_visibility): ...this.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-04-27 17:20:09 +02:00
Giuliano Procida
4e11174eae abidiff: Omit declaration-only type size 0 diffs.
When reporting declaration-only type changes, the size is reported as
changing to or from 0, which is not correct. The declaration type is
of unknown size. This patch eliminates such size reports.

	* src/abg-reporter-priv.cc (report_size_and_alignment_changes):
	Filter out declaration-only / defined type size changes
	unconditionally.
	* tests/data/test-abidiff-exit/test-decl-struct-report.txt:
	Update test.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-04-27 13:12:48 +02:00
Giuliano Procida
39ab7e8b22 abidiff: Blank line after declaration-only diff.
In the case where a type change is summarised as declaration-only to
defined or vice versa, the trailing new line was missing.

	* src/abg-default-reporter.cc (default_reporter::report): In
	the class_or_union_diff overload, emit a new line at the end
	of the declaration-only reporting path.
	* tests/data/test-abidiff-exit/test-decl-struct-report.txt:
	Add missing blank lines.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-04-27 13:02:02 +02:00
Giuliano Procida
bddb6b7d09 Add tests for declaration-only struct diffs.
There were no tests exercising this reporting path. The new test is
run with --harmless as these changes are considered harmless.

	* tests/data/Makefile.am: Add new test case files.
	* tests/data/test-abidiff-exit/test-decl-struct-report.txt:
	New test case generating "declaration-only" output.
	* tests/data/test-abidiff-exit/test-decl-struct-v0.c: Ditto.
	* tests/data/test-abidiff-exit/test-decl-struct-v0.o: Ditto.
	* tests/data/test-abidiff-exit/test-decl-struct-v1.c: Ditto.
	* tests/data/test-abidiff-exit/test-decl-struct-v1.o: Ditto.
	* tests/test-abidiff-exit.cc: Run new test case.

Signed-off-by: Giuliano Procida <gprocida@google.com>
2020-04-27 12:48:58 +02:00
Mark Wielaard
b8860e1db3 Add --no-elf-needed option to drop DT_NEEDED list from corpus.
The elf-needed list is not relevant for the exported ABI of a library
so provide an option to drop it.

	* doc/manuals/abidw.rst: Document --no-elf-needed.
	* include/abg-writer.h (set_write_elf_needed): New function.
	(set_common_options): Call it.
	* src/abg-writer.cc (write_context::m_write_elf_needed): New data
	member.
	(write_context::{g,s}et_write_elf_needed): Add new accessors.
	(set_write_elf_needed): New function.
	(write_context::write_corpus): Check write_elf_needed.
	* tools/abidw.cc (options): Add write_elf_needed bool.
	(display_usage): Describe --no-elf-needed.
	(parse_command_line): Parse --no-elf-needed.

Signed-off-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-04-24 15:59:30 +02:00