Commit Graph

203 Commits

Author SHA1 Message Date
Ondrej Oprala
c05a02573f Document abipkgdiff's option --no-abignore
* doc/manuals/abipkgdiff.rst: Mention the new option.
	* tools/abipkgdiff.cc: Likewise.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2015-11-10 09:50:45 +01:00
Dodji Seketeli
6d4472066b Make abidw --abidiff not show definitely harmless changes
When comparing the ABI of the input ELF binary with that same ABI
saved to abixml and read back again, there can be some minor and
harmless changes that are seen, because libabigail makes some
approximations for performance reasons.  For instance, if there are
two types that are equivalent, but have different names (because of
typedefs) then libabigail will consider that they are the same type,
and might save them (to abixml) and read them back (from abixml) in
different order.

That can lead to subtle changes that are reported (and filtered out)
by the command "abidw --abixml".

This patch arranges for abidw --abixml to avoid emitting a report
saying that a filtered out change was detected, as those cases are
considered OK.

The patch also fixes a little issue where abidw would abort because
the user forgot to provide the binary to analyze, on the command line.

	* tools/abidw.cc (set_diff_context): New function.
	(main): Use that new function.  Do not show any output for
	--abidiff if only compatible changes were detected.  Also, do not
	abort if no input binary was giving.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-10-15 13:50:49 +02:00
Ondrej Oprala
b2a5bf6389 Bug 19082 - Recognize suppression spec files
When abipkgdiff is invoked on a set of packages, the newer (second) one is also
inspected for files matching the pattern '*.abignore', whose contents are read
and interpreted as suppression specifications.

	* tests/data/Makefile.am: Add new test material to the build system.
	* tests/data/test-diff-pkg/dirpkg-{0-dir1,{1,2}-dir2}/dir.abignore:
	A test suppression specification.
	* tests/data/test-diff-pkg/dirpkg-{2,3}-dir2/.abignore: Likewise.
	* tests/data/test-diff-pkg/dirpkg-3.suppr: Likewise.
	* tests/data/test-diff-pkg/dirpkg-{1,2,3}-dir{1,2}/libobj-v0.so: New
	binary test inputs.
	* tests/data/test-diff-pkg/dirpkg-{1,2,3}-dir{1,2}/obj-v0.cc: New test
	source files
	* tests/data/test-diff-pkg/dirpkg-{1,2,3}-report-{0,1}.txt: New
	reference outputs
	* tests/test-diff-pkg.cc: Adjust to run the new tests.
	* tools/abipkgdiff.cc (prog_options): New static pointer to struct
	opts.
	(file_tree_walker_callback_fn): Rename to
	first_package_tree_walker_callback_fn.
	(second_package_tree_walker_callback_fn): Check for ELF files just
	like the previous function but additionally check for files
	ending with ".abignore", unless disabled from the command line.
	({create_maps_of_package,extract_package_and_map_its}_content):
	Add a callback as a new argument.
	(main) handle the new "--no-abignore" option, which turns off
	the search for suppression files within the new package.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2015-10-13 09:19:47 +02:00
Dodji Seketeli
133d0e491d Remove some dead code in abilint
* tools/abilint.cc (options::bidiff): Remove.
	(options::options): Adjust.
	(display_usage): Remove usage string for --bidiff
	(parse_command_line): Remove parsing of un-implemented option
	--bidiff.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-09-21 15:20:10 +02:00
Dodji Seketeli
bd0926a2b5 Add a new --abidiff option to abidw
This is a debugging and sanity check option.  It saves the abi of the
ELF binary to a temporary file, reads it back and compares the abis of
the temporary file against the abi of the input ELF binary.

	* tools/abidw.cc (options::abidiff): New data member.
	(options::options): Initialize it.
	(display_usage): Add a usage string for the new --abidiff option.
	(parse_command): Parse the new --abidiff options.
	(main): Save the abi of the input elf in a temporary abixml file;
	read it back and compare both.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-09-21 15:14:26 +02:00
Dodji Seketeli
04167e5c66 Fix compilation warnings in abipkgdiff.cc
* tools/abipkgdiff.cc (package::erase_extraction_directory)
	(extract_rpm, extract_deb, extract_tar)
	(erase_created_temporary_directories_parent): Check the return
	value of the system() function.
	(extract_package): Add necessary white space.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-09-09 14:20:43 +02:00
Dodji Seketeli
a717ca6faf Adjust {s,g}et_show_stats() to use a reference
* include/abg-dwarf-reader.h ({s,g}et_show_stats): Use a reference
	to the reader.
	* tools/abidiff.cc (main): Adjust.
	* tools/abidw.cc (main): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-09-07 23:42:17 +02:00
Dodji Seketeli
b2e5366d3f Introduce the concept of environment
There are resources needed by the type system and other artifacts of
libabigail.  Today, when the life time of those resources need to be
greater than all of artifacts of Abigail, then said resources are made
global.

But then global resources are not great, if anything because they
complicate the future use of the library in concurrent computing
setups.

As I was in the need to add one resource to be used by the type
system, I decided to sit down and first overhaul how these long lived
resources needed to be handled.

And here comes the concept of "environment".  An environment is a
place where one can put resources that need to live longer than all
the other artifacts of the Abigail system.  And so, the code that
creates Abigail artifacts needs and environment of for said artifacts
to use.  In other words, artifacts now use an environment.

This has interesting and strong implications.  We can only compare two
artifacts if they use the same environment.  This is quite a strong
requirement.

But then when this requirement is fulfilled, comparing two types
amounts to just comparing two pointer values; hash values for types
can also be cached.  Now *that* is great for speed of comparison, is
it not?

This patch introduce the concept environment (which is basically a new
abigail::ir::environment type), removes the global variables and uses
the environment instead.  Each ABI artifact (either type or decl) now
has a ::get_environment() member function to get its environment.

This patch also disables the caching of hash values because the
caching must happen only *after* all types have been canonicalized.
We were not respecting that requirement until now, and that introduces
wrong hash values.  A subsequent patch is going to re-introduce hash
value caching again, once the infrastructure is in place to set a flag
in the environment (hah!) once type canonicalization is done, and then
later read that flag when some client code requests a hash value, to
know if we should look in the hash value cache or not.

The patch obviously changes the output of numerous regression tests
(if anything b/c it disables hash value caching) so 'make check'
yields regressions.  But then, it's only the subsequent patch that
updates the tests.

	* include/abg-ir.h: Adjust note about memory management.
	(class environment): Declare new class.
	(translation_unit::translation_unit): Take an environment in
	parameter.
	(translation_unit::{g,s}et_environment): Declare new member
	functions.
	(type_or_decl_base::{g,s}et_environment): Likewise.
	(type_or_decl_base::{get_cached_hash_value,
	set_cached_hash_value}): Change the name of
	decl_base::peek_hash_value() and decl_base::set_hash() here into
	these and move them here.
	(type_or_decl_base::hashing_started): Move
	decl_base::hashing_started() here.
	({g,s}et_environment_for_artifact): Declare new functions.
	(class decl_base): Move member functions hashing_started(),
	peek_hash_value() and set_hash() on to the type_or_decl_base base
	class.
	(scope_decl::scope_decl): Initialize the virtual member
	type_or_decl_base().
	(type_decl::{get_void_type_decl,
	get_variadic_parameter_type_decl}): Remove these static member
	functions.  They are now non-static member functions of the new
	environment type.
	* src/abg-ir.cc (class environment_setter): New internal class.
	(get_canonical_types_map): Remove.  This now becomes a member
	function of the environment type.
	(class usage_watchdog): Remove.
	(usage_watchdog_{s,w}ptr): Remove these typedefs.
	(get_usage_watchdog_wptr, ref_usage_watchdog)
	(maybe_cleanup_type_system_data): Remove these functions.
	(translation_unit::priv::usage_watchdog_): Remove data member.
	(translation_unit::priv::env_): New data member.
	(translation_unit::priv::priv): Take an environment and initialize
	the new env_ data member.  Do not initialize the removed
	usage_watchdog_.
	(translation_unit::translation_unit): Take an environment
	parameter.
	(translation_unit::get_global_scope): Set the environment of a new
	global scope.
	(translation_unit::{g,s}et_environment): New accessors.
	(translation_unit::bind_function_type_life_time): Set the
	environment of the function type.
	(struct environment::priv): New class.
	(environment::{environment, ~environment, get_canonical_types_map,
	get_variadic_parameter_type_decl, canonicalization_is_done}): New
	member functions.
	(struct type_or_decl_base::priv): New class.
	(type_or_decl_base::{type_or_decl_base, hashing_started,
	get_cached_hash_value, set_cached_hash_value, set_environment,
	get_environment, traverse}): New member functions.
	({s,g}get_environment_for_artifact): New functions.
	(decl_base::priv::{hash_, hashing_started}): Remove.
	(decl_base::priv::priv): Adjust.
	(decl_base::decl_base): In the copy constructor, initialize the
	virtual base type_or_decl_base.  Do not initialize hash_ and
	hashing_started data member that got removed.
	(decl_base::{hashing_started, peek_hash_value, set_hash}): Remove
	member functions.
	(strip_typedef): Set the environment of the new type which has its
	typedefs stripped off.  Adjust the call to type_or_void().
	(scope_decl::{add, insert}_member_decl): Set the environment of
	the new member decl to the environment of its scope.
	(synthesize_type_from_translation_unit)
	(synthesize_function_type_from_translation_unit): Set the
	environment for the newly synthesized type. Adjust calls to
	type_or_void().
	(type_or_void): Take an environment in parameter.  Get the void
	type from the environment.
	(get_canonical_types_map): Remove.
	(type_base::get_canonical_type_for): Get the canonical types map
	from the environment, not from a global variable.
	(type_decl::{get_void_type_decl,
	get_variadic_parameter_type_decl}): Remove.
	(pointer_type_def::pointer_type_def): Adjust call to type_or_void.
	(reference_type_def::reference_type_def): Likewise.
	(function_decl::parameter::get_pretty_representation): Get the
	variadic parameter type decl from the environment.
	(class_decl::priv::classes_being_compared_): Remove static data
	member.
	(class_decl::priv::{mark_as_being_compared,
	unmark_as_being_compared, comparison_started): Use the "classes
	being compared" map from the environment.
	(class_decl::base_spec::get_hash): Adjust.
	(keep_type_alive): Get the alive types array from the environment)
	not from a global variable anymore.
	(get_next_string): Put the counter in thread-local storage.
	* src/abg-hash.cc (scope_decl:#️⃣:operator())
	(function_decl:#️⃣:operator()): Do not handle caching (here).
	* include/abg-corpus.h (corpus::{g,s}et_environment): Declare new
	accessors.
	* src/abg-corpus.cc (corpus::priv::env): New data member.
	(corpus::priv::priv): Initialize it.
	(corpus::corpus):  Take an environment in parameter.
	(corpus::{g,s}et_environment): Define new member functions
	(corpus::add): Set the environment of the newly added translation
	unit, if it's not set already set.  In any case, assert that the
	translation unit must use the same environment as the corpus.
	* include/abg-dwarf-reader.h (create_read_context)
	(read_corpus_from_elf): Take an environment parameter.
	({s,g}et_debug_info_root_path, {s,g}et_environment): Declare new
	functions.
	* src/abg-dwarf-reader.cc (read_context::{env_,
	offline_callbacks_}): New data members.
	(read_context::read_context): Initialize them.
	(read_context::clear_per_translation_unit_data): Do not touch the
	void type declaration, it doesn't belong to the translation unit.
	(read_context::{env, offline_callbacks}): New accessors.
	(read_context::{create_default_dwfl}): New member function.
	(read_context::dwfl_handle): Add a setter overload.
	({s,g}et_debug_info_root_path): Define new accessors.
	(create_default_dwfl, create_dwfl_sptr, create_default_dwfl_sptr):
	Remove these.
	(build_translation_unit_and_add_to_ir): Adjust to pass the
	environment to the newly created translation unit.
	(build_function_decl): Adjust to pass the environment to the
	created function and parameter types.  Get variadic parameter type
	node from the current environment, not from a global variable.
	And do not try to canonicalize function types here.
	(read_debug_info_into_corpus): Set the environment of the newly
	created corpus.
	(build_ir_node_for_void_type): Get the void type node from the
	current environment, rather than from a global variable.
	(create_read_context): Take the environment in parameter.
	Create the default dwarf front end library handle using the new
	member function of the read context.  Set the current environment
	used by the reader.
	(read_corpus_from_elf): Take an environment in
	parameter. Overhaul.  This is now simpler.
	(has_alt_debug_info): Adjust the call to create_read_context() to
	make it pass an empty environment.
	* include/abg-fwd.h (class environment): Forward declare.
	* include/abg-reader.h (read_translation_unit_from_file)
	(read_translation_unit_from_buffer)
	(read_translation_unit_from_istream)
	(read_corpus_from_native_xml): Take an environment in parameter.
	* src/abg-reader.cc (read_context::m_env): New data member.
	(read_context::read_context): Initialize it.
	(read_context::{get_environment, set_environment}): New data
	member.
	(read_translation_unit): Set environment of the new translation
	unit.
	(read_corpus_from_input): Set the environment of the new corpus.
	(read_translation_unit_from_file)
	(read_translation_unit_from_buffer)
	(read_translation_unit_from_istream, read_corpus_from_native_xml):
	Take an environment in parameter.
	(build_function_parameter): Get variadic parameter type from the environment.
	* src/abg-comparison.cc (compute_diff): Add asserts in all the
	overloads to ensure that the artifact being compared come from the
	same environment.
	* tests/print-diff-tree.cc (main): Create an env for the ABI
	artifacts to use.
	* tests/test-abidiff.cc (main): Likewise.
	* tests/test-diff-dwarf.cc (main): Likewise.
	* tests/test-ir-walker.cc (main): Likewise.
	* tests/test-read-dwarf.cc (main): Likewise.
	* tests/test-read-write.cc (main): Likewise.
	* tools/abicompat.cc (main): Likewise.
	* tools/abidiff.cc (main): Likewise.
	* tools/abidw.cc (main): Likewise.
	* tools/abilint.cc (main): Likewise.
	* tools/abipkgdiff.cc (main): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-09-07 23:35:29 +02:00
Dodji Seketeli
277e524392 Add a new --noout option to abidw
* tools/abidw.cc (options::noout): New data member.
	(options::options): Initialize it.
	(display_usage): Add a usage string for the new option.
	(parse_command_line): Parse the new option.
	(main): If --noout is provided, do not emit the XML form.
 	* doc/manuals/abidw.rst: Document the new option.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-29 16:23:15 +02:00
Dodji Seketeli
e61afa7291 Add a --no-architecture option to abidiff
This new option omits architectures when comparing ABIs.

	* tools/abidiff.cc (options::no_arch): New data member.
	(options::options): Initialize it.
	(display_usage): Display a help string for the new options.
	(parse_command_line): Parse the new options.
	(main): If --no-architecture is provided, set the corpus
	architecture to "".
	* doc/manuals/abidiff.rst: Document the new options.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-29 16:23:15 +02:00
Dodji Seketeli
72b42c3090 Misc style cleanups
* configure.ac: Fix some spelling typos.
	* src/abg-tools-utils.cc (guess_file_type): Fix indentation.
	* tests/test-diff-pkg.cc (int_out_specs): Add some vertical spaces
	for better legibility.
	* tools/abidiff.cc (main): Add a missing space.
	* tools/abipkgdiff.cc (extract_deb): Fix a typo in the comment.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-22 14:32:20 +02:00
Dodji Seketeli
585fc4c33c Make abipkgdiff compare tar archives containing binaries
This patch adds support for comparing the ABI of binaries contained in
a tar archive.

If the archive is compressed with gzip, bzip2, lzip, lzma or xz, then
abipkgdiff recognizes the usual relevant file extensions and lets the
GNU tar program handle the decompression.

If the archive is not compressed, abipkgdiff recognizes the UStar
(Uniform Standard Tape ARchive) format, even if the archive file name
doesn't end with the .tar extension, and lets the GNU tar program
handle the extraction.  If the file ends up with the .tar extension
anyway (even if it's not in the UStar format, abipkgdiff lets the GNU
tar program handle its extraction.

	* config.h.in (WITH_TAR): New configuration preprocessor macro.
	* configure.ac: Add a new --enable-tar option.  It's turned on
	automatically if the tar program is found in the PATH.  Adjust the
	build configuration report to add the tar archive support.
	* include/abg-tools-utils.h (string_ends_with): Declare new
	function.
	(enum file_type): Add a new FILE_TYPE_TAR enumerator.
	* src/abg-tools-utils.cc (string_ends_with): Define new function.
	(operator<<(ostream&, file_type)): Serialize the new FILE_TYPE_TAR
	enumerator.
	(guess_file_type): Detect UStar format file by reading its magic
	number.  Detect compressed tar files based on the file path
	extension.
	* tools/abipkgdiff.cc (extract_tar): Define new function.
	(extract_package): Handle tar packages.
	(main): Handle tar archives.
	* tools/abidiff.cc (main): Handle the new FILE_TYPE_TAR
	enumerator.
	* tools/abilint.cc (main): Likewise.
	* tests/data/test-diff-pkg/tarpkg-0-dir{1,2}.ta{,r,.bz2, gz}: New
	test input tarballs.
	* tests/data/test-diff-pkg/tarpkg-0-report-0.txt: New test output
	reference.
	* tests/data/Makefile.am: Add the new test data file above to
	source distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add new tests cases.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-22 14:32:20 +02:00
Dodji Seketeli
fca8506ab9 Misc style fixes in abipkgdiff
* include/abg-tools-utils.h (enum file_type): Fix the comment for
	for the FILE_TYPE_DEB enumerator.
	* tools/abipkgdiff.cc (main): Fix the style of the conditions.
	Also, fix the text emitted.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-22 12:19:27 +02:00
Dodji Seketeli
d7dbbf0d50 Make abipkgdiff compare directories containing binaries
abipkgdiff knows how to compare the ABI of binaries contained in .deb
and .rpm files.  This patch adds support for comparing the ABI of
binaries contained in two directories.

	* include/abg-tools-utils.h (enum file_type): Add a new
	FILE_TYPE_DIR enumerator.
	* src/abg-tools-utils.cc (operator<<(ostream&, file_type)):
	Support serialization of the new FILE_TYPE_DIR enumerator.
	(guess_file_type): Detect that the path given is a directory.
	* tools/abipkgdiff.cc (package::package): If the package is a
	directory, then set its extracted directory path to the path of
	the directory.
	(package::erase_extraction_directory): Do not erase the extraction
	directory if the package is a directory provided by the user.
	(extract_package): If the package is a directory provided by the
	user, then there is nothing to extract.
	(main): If the first package is a directory, then the second one
	should be a directory as well.
	* tools/abidiff.cc (main): Support directories as input.
	* tools/abilint.cc (main): Likewise.
	* tests/data/test-diff-pkg/dirpkg-0-dir{1,2}/libobj-v0.so: New
	binary test inputs.
	* test/data/test-diff-pkg/dirpkg-0-report-0.txt: New input test
	file.
	* tests/data/test-diff-pkg/dirpkg-1-dir{1,2}/obj-v0.cc: Source
	code of the binary test inputs above.
	* tests/data/Makefile.am: Add the new files above to the source
	distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the new test input
	files above to the set of tests this harness has to run over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-22 12:19:27 +02:00
Dodji Seketeli
d1c6ef0cb5 make abipkgdiff compile with GCC 4.4.7
GCC 4.4.7 won't let us declare an instance of string with __thread.
So for now, package::extracted_packages_parent_dir() juststores its string
globally.  We are single-threaded for now anyway.

	* tools/abipkgdiff.cc (package::extracted_packages_parent_dir):
	The string holding the dir name is no more __thread, as this won't
	compile with GCC 4.4.7

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-21 13:08:38 +02:00
Dodji Seketeli
7bcaf67504 Add a --stats to abidiff and abidw
For now, this new --stats emits diagnostics about the number of types
canonicalized at the very end of building the ABI corpus as well as
the number of types that were scheduled for late canonicalizing and
that couldn't be canonicalized.

	* include/abg-dwarf-reader.h (get_show_stats)
	(set_show_stats): New accessors for a new "show_stats" property of
	the dwarf reader context.
	* src/abg-dwarf-reader.cc: Include iostream to use std::cerr.
	(dwarf_reader::show_stats_): New data member.
	(dwarf_reader::dwarf_reader): Initialize it.
	(dwarf_reader::show_stats)
	(get_show_stats)
	(set_show_stats): Define new accessors.
	(dwarf_reader::die_type_map): Add const overload to this accessor.
	(dwarf_reader::lookup_type_from_die_offset): Make this accessor
	const.
	(dwarf_reader::add_late_canonicalized_types_stats): New member
	function.
	(dwarf_reader::perform_late_type_canonicalizing): Emit the
	statistics about late-canonicalized types if the user asked for
	it.
	* tools/abidiff.cc (options::show_stats): New data member.
	(options::options): Initialize it.
	(display_usage): Document it.
	(parse_command_line): Parse the new --stats option.
	(main): Create a dwarf reader context, set the show_stats to it
	and then use that context to read the corpora before diffing them.
	* tools/abidw.cc (options::show_stats): New data member.
	(options::options): Initialize it.
	(display_usage): Document it.
	(parse_command_line): Parse the new --stats option.
	(main): Set the show_stats to the dwarf reader context before
	using it.
	* doc/manuals/abidiff.rst: Update the manual.
	* doc/manuals/abidw.rst: Update the manual.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-20 13:25:42 +02:00
Dodji Seketeli
dd15667e8e Fix typos in abipkgdiff
* tools/abipkgdiff.cc (display_usage): s/pompare/compare.  Give a
	better help message for --help.
	(extract_rpm): Insert a space after the path of the package being
	extracted, when emitting a verbose message.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-14 16:50:18 +02:00
Dodji Seketeli
57e2cb9e07 Update comment about the supported formats in abipkgdiff
* tools/abipkgdiff.cc: Now that .deb packages are supported, say
	it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-14 15:24:12 +02:00
Dodji Seketeli
28090bad1b Make the support of RPM and DEB package formats conditional
If at configure time the libabigail source tarball detects that
rpm2cpio and cpio are present then it enables the support for rpm
files.  Users can explicitly enable or disable that support by passing
--enable-rpm or --disable-rpm to configure.

Similarly if it detects that dpkg is present at configure time then it
enables the support for deb files.  Users can explicitly enable or
disable that support by passing --enable-deb or --disable-deb to
configure.

	* config.h.in: Define WITH_DEB and WITH_RPM pre-processor macros.
	* configure.ac: Add --enable-{rpm,deb} switches.  Check for
	rpm2cpio and cpio programs, unless --disable-rpm was provided.  If
	they are found and if --enable-rpm=auto was provided, then
	consider that --enable-rpm=yes was provided.  In that case, set
	the WITH_RPM macro to 1.  Otherwise, undefine that macro.
	Similarly, check for dpkg unless --disable-deb was provided.  If
	it's found and if --enable-deb=auto was provided, consider that
	--enable-deb=yes was provided.  In that case, set the WITH_DEB
	macro to 1.  Otherwise, undefine that macro.  Define the
	ENABLE_RPM and ENABLE_DEB conditional automake variables, if the
	rpm resp. deb support is enabled.  Emit a notice about the rpm and
	deb features being enabled or not, at the end of the configure
	process.
	* tests/test-diff-pkg.cc: Include the config.h header.
	(in_out_spec): Guard rpm tests by the WITH_RPM macro.  Similarly,
	guard deb tests by the WITH_DEB macro.
	* tools/abipkgdiff.cc: Include the config.h header.
	(extract_rpm): Guard this function definition with the WITH_RPM
	macro.
	(extract_deb): Guard this function definition with the WITH_DEB
	macro.
	(extract_package): Guard the handling of rpm packages with the
	WITH_RPM macro and the handling of deb package with the WITH_DEB
	macro.  If a package not-support package format is encountered,
	emit an appropriate error message and error out.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-14 13:40:32 +02:00
Matthias Klose
4df0a4d952 Add support for .deb files to abipkgdiff
This lets abipkgdiff compare debian binary packages.

The patch contains test cases for debian package with split debug info
that is referenced by the build-id scheme.  These test cases come from
the bug report https://sourceware.org/bugzilla/show_bug.cgi?id=18792,
more particularly from the attachment
https://sourceware.org/bugzilla/attachment.cgi?id=8516.

	* include/abg-tools-utils.h (file_type): Add FILE_TYPE_DEB.
	* tools/abipkgdiff.cc (extract_deb): New.
	(extract_package, main): Handle FILE_TYPE_DEB.
	* src/abg-tools-utils.cc (operator<<): Handle FILE_TYPE_DEB.
	(guess_file_type): Detect FILE_TYPE_DEB.
	* tools/abidiff.cc (main): Handle FILE_TYPE_DEB.
	* tools/abilint.cc (main): Handle FILE_TYPE_DEB.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a-dbgsym_2.4.0-1_amd64.ddeb:
	Input debian debug info package; to be compared by the test
	harness runtestdiffpkg.
	* tests/data/test-diff-pkg/libsigc++-2.0-0c2a_2.4.0-1_amd64.deb:
	Input debian package; to be compared by the test harness
	runtestdiffpkg.
	* tests/data/test-diff-pkg/libsigc++-2.0-0v5-dbgsym_2.4.1-1ubuntu2_amd64.ddeb:
	Input debug info package
	* tests/data/test-diff-pkg/libsigc++-2.0-0v5_2.4.1-1ubuntu2_amd64.deb:
	Input debian package; to be compared by the test harness
	runtestdiffpkg.
	* 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:
	Reference output for the comparison of the packages above.
	* tests/data/Makefile.am: Add the new files above to the source distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the input packages
	above to the set of files to be compared by this test harness.

Signed-off-by: Matthias Klose <doko@debian.org>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-14 13:36:23 +02:00
Dodji Seketeli
56112bae3b Add an abipkgdiff --fail-no-dbg command line option
* tools/abipkgdiff.cc (options::fail_if_no_debug_info): New data
	member.
	(options::options): Initialize it.
	(display_usage): Document it.
	(compare): If the user asked for it, fail if the we couldn't file
	the debug info for the corpus files being compared.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-13 23:26:53 +02:00
Dodji Seketeli
c09bb53ab1 Add -h and -d option shortcuts to abidw
Added a -h option shortcut for the --help option and a -d option
shortcut for the --debug-info-dir option, to the abidw program.

	* tools/abidw.cc (display_usage): Added a documentation string.
	(parse_command_line): Parse the new -h and -d shortcuts.
	* doc/manuals/abidw.rst: Update the manual.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-13 23:26:53 +02:00
Dodji Seketeli
71acc72064 Add a -h option shortcut to abidiff
Added a -h shortcut for --help to the abidiff program.n

	* tools/abidiff.cc (display_usage): Add documentation for the new
	switch.
	(parse_command_line): Parse the -h option.
	* doc/manuals/abidiff.rst: Update the manual.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-13 23:26:53 +02:00
Dodji Seketeli
da870f3598 Add a -h shortcup to abipkgdiff --help
* tools/abipkgdiff.cc (display_usage): Document the -h shortcut.
	(parse_command_line): Parse the -h shortcut to --help.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-13 23:26:52 +02:00
Dodji Seketeli
9f7c07460d Add --no-added-syms to abipkgdiff
With this new option the tool ignores added functions, variables and
their symbols.

	* tools/abipkgdiff.cc (options::show_added_syms): New data member.
	(options::options): Initialize it.
	(parse_command_line): Parse the new --no-added-syms option and set
	the options::show_added_syms flag accordingly.
	(display_usage): Add a help string for the new option.
	(set_diff_context_from_opts): Set the diff context according to
	the state of the new options::show_added_syms flag.
	* doc/manuals/abipkgdiff.rst: Add manual entry for the new
	--no-added-syms options.
	* tests/data/test-diff-pkg/test-rpm-report-5.txt: New test
	reference input file.
	* tests/data/Makefile.am: Add the new file above to source
	distribution.
	* tests/test-diff-pkg.cc (InOutSpec::prog_options): New data
	member.
	(in_out_specs): Adjust.  Add a new input to run the test again
	with --no-added-syms.
	(main): Adjust to pass the program options contained in
	InOutSpec::prog_options to abipkgdiff.

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

fixup! Add --no-added-syms to abipkgdiff

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-06 15:22:38 +02:00
Dodji Seketeli
f0d319ab42 Make abipkgdiff erase the *parent* directory of temporary files
abipkgdiff was erasing the temporary files created by it wasn't
erasing the parent directory containing them.  Fixed thus.

	* tools/abipkgdiff.cc
	(erase_created_temporary_directories_parent): New static function.
	(compare): After comparison, erase the temporary parent directory
	as well.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-24 14:09:55 +02:00
Dodji Seketeli
b8ae34192f Extract all packages for a given run of abipkgdiff under the same temp dir
This patch extracts all packages for a given run of abipkgdiff under
the same temporary directory, cluttering /tmp less.

To do this, the patch makes accesses of data members of the 'package'
type go through accessor functions only.  Then the accessor for the
parent directory of all extracted package does the job of computing
the path to that parent directory in a way that makes it unique, per
thread.

	* tools/abipkgdiff.cc (package::{<all data members>}): Make the
	data members be private.  Make their names end with an underscore.
	(package::extracted_package_parent_dir_path): Remove.
	(package::extracted_package_dir_path): Rename into
	package::extracted_dir_path_.
	(package::extracted_packages_parent_dir): New static member
	function, accessor.
	(package::package): Adjust to the new names of the data members.
	Call the new package::extracted_package_parent_dir() static member
	function to initial the package::extracted_dir_path_ data member.
	(package::{path, extracted_dir_path, type, is_debug,
	path_elf_file_sptr_map, debug_info_package}): New accessors for
	the data members.
	(package::{erase_extraction_directory,
	erase_extraction_directories}): Adjust.
	(erase_created_temporary_directories)
	(create_maps_of_package_content)
	(extract_package_and_map_its_content, prepare_packages, compare)
	(main): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-22 16:05:11 +02:00
Dodji Seketeli
decf33e847 Add a --keep-tmp-files option to abipkgidff
Sometimes, for debugging purposes it can be very handy to inspect the
content of the packages as seen by the tool.  This patch thus adds a
new --keep-tmp-files options so that users can inspect the content of
packages that were extracted.

	* tools/abipkgdiff.cc (options::keep_tmp_files): New data member.
	(options::options): Initialize it.
	(display_usage): Display a usage string for the new
	--keep-tmp-files option.
	(parse_command_line): Parse the new --keep-tmp-files option.
	(compare): Do not erase temporary directories if the users asked so.
	* doc/manuals/abipkgdiff.rst: Document the new --keep-tmp-files
	options.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-22 15:36:16 +02:00
Dodji Seketeli
819f8941cf Show linkage names in abipkgdiff output
With this patch abipkgdiff now shows the linkage names of
added/removed functions and variables.  In addition, there now is a
--no-linkage-name option to avoid seeing linkage names.

	* doc/manuals/abipkgdiff.rst: Document the new --no-linkage-name
	options.
	* tools/abipkgdiff.cc (options::show_linkage_names): New data
	member.
	(options::options): Initialize it.
	(display_usage): Display a usage string for --no-linkage-name.
	(parse_command_line): Parse the --no-linkage-name option.
	(set_diff_context_from_opts): Set the diff context accordingly.
	* tests/data/test-diff-pkg/test-rpm-report-0.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-21 16:09:53 +02:00
Dodji Seketeli
b638309e48 Add --no-added-binaries to abipkgdiff
* tools/abipkgdiff.cc (options::show_added_binaries): New data
	member.
	(options::options): Initialize it.
	(display_usage): Add a help string for --no-added-binaries.
	(parse_command_line): Parse the new --no-added-binaries option.
	(compare): Do not show added binaries if the user doesn't want to.
	* doc/manuals/abipkgdiff.rst: Document the new --no-added-binaries
	option.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-21 14:15:33 +02:00
Dodji Seketeli
96af1baf13 make abipkgdiff return a proper exit code
With this patch, abipkgdiff returns the same exit code as abidiff.
It's zero if there is no ABI change, and non-zero if there are ABI
changes.  The exact value depends on the kind of changes that is
detected.

	* tools/abipkgdiff.cc (compare): Return an instance
	abigail::tools_utils::abidiff_status, just like what we do in
	abidiff.
	* doc/manuals/abipkgdiff.rst: Document the new exit code.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-21 14:11:53 +02:00
Dodji Seketeli
6d4c194c04 Fix logic of determining if changes happened in abidiff
Now that we can easily check if the diff between two corpora carries
net changes (i.e, changes after applying suppression specifications)
we can simplify the logic of determining if the corpora have
"worthwhile" changes, in abidiff.

	* tools/abidiff.cc (main): Simplify the logic when determining if
	the comparison between two corpora yields worthwhile changes.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-21 12:54:57 +02:00
Dodji Seketeli
92b821034a Clean up the output of abicompat weak mode
Remove ugly vertical spaces from the output of abicompat in weak
mode and adjust regression tests accordingly.

	* tools/abicompat.cc (perform_compat_check_in_weak_mode): Remove
	disgracious vertical spaces in the wording.
	* tests/data/test-abicompat/test5-fn-changed-report-0.txt: Adjust.
	* tests/data/test-abicompat/test6-var-changed-report-0.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-20 16:01:27 +02:00
Sinny Kumari
ab1316bcbc Display --suppressions|--suppr option in help usage
* tools/abipkgdiff.cc (display_usage): Print
	 --suppressions|--suppr <path> option in help usage

Signed-off-by: Sinny Kumari <sinny@redhat.com>
2015-07-20 12:47:07 +02:00
Dodji Seketeli
78e7890b20 Fix the wording of description of abipkgdiff.cc again
* tools/abipkgdiff.cc: Fix the wording again.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-20 10:15:00 +02:00
Dodji Seketeli
f681c33970 Remove use of tmpnam from abilint
We were using the unsafe tmpnam function in abilint.  This patch
creates a helper type abigail::tools_utils::temp_file that does away
with the use tmpnam in abilint.

	* include/abg-tools-utils.h (abigail::tools_utils::temp_file):
	Declare new type.
	(abigail::tools_utils::temp_file_sptr): New typedef.
	* src/abg-tools-utils.cc (temp_file::priv): Define new type.
	(temp_file::{temp_file, is_good, get_path, get_stream, create}):
	Define new member functions.
	* tools/abilint.cc (main): Do not use tmpnam anymore.  Use the new
	abigail::tools_utils::temp_file type instead.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-20 10:06:17 +02:00
Dodji Seketeli
1ddde3d9d0 Try to avoid a race condition when abipkgdiff extracts packages.
abipkgdiff extracts the content of the first package in a directory
named <tmpdir>/package1 and the content second package in
<tmpdir>/package2.  If two independant instances of abipkgdiff are
launched at the same time, they are going to walk on each others'
toes, to say the least.

This patch extracts the content of each package in directory named
<tmpdir>/<randomname>/package1, where randomname is supposed to be a
random number, and so should be unique, most of the time.

I guess we should try harder to generate a randomname that is unique
when we see that the directory <tmpdir>/<randomname> exists already,
but for now, what we have is good enough, or at least better than what
we have had so far.

	* include/abg-tools-utils.h (get_random_number)
	(get_random_number_as_string): Declare new functions.
	* src/abg-tools-utils.cc (get_random_number)
	(get_random_number_as_string): Define them.
	* tools/abipkgdiff.cc
	(package::extracted_package_parent_dir_path): New data member.
	(package::package): Initialize
	package::extracted_package_parent_dir_path to
	<tmpdir>/<randomname>, with randomname being a random number
	represented as a string.
	(extract_rpm): Make sure to create a hierarchy of directories, not
	just a directory.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-20 00:02:00 +02:00
Dodji Seketeli
77fa0621e4 Fix the wording of the description of the abipkgdiff.cc file
* tools/abipkgdiff.cc: Fix the wording of the description.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-19 19:54:57 +02:00
Dodji Seketeli
80dc31f540 Add --suppressions to abipkgdiff
* tools/abipkgdiff.cc (options::suppressions): New data member.
	(set_diff_context_from_opts): Set the suppression specifications
	provided by the user to the diff context.
	(parse_command_line): Parse the --suppressions and --suppr command
	line options.
	* doc/manuals/abipkgdiff.rst: Document the --suppressions and
	--suppr options.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-19 19:52:01 +02:00
Dodji Seketeli
7f67f2573d Fix the --verbose option
When a binary cannot be analyzed by abipkgdiff, silently skip it
unless --verbose is used, in which case, display a message saying
that it couldn't be analyzed.

	* tools/abipkgdiff.cc (compare): In the elf_file overload, do not
	emit an error message when a binary could not be analyzed unless
	--verbose was provided.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:11:36 +02:00
Dodji Seketeli
317f4e1ff3 Cleanup the output for added/removed binaries
* tools/abipkgdiff.cc (compare): In the overload for packages,
	indent the content of the "Removed binaries" and "Added binaries"
	paragraphs.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:11:24 +02:00
Dodji Seketeli
3b85f2864d Avoid redundant diff report messages by default.
Just like what abidiff does, this patch avoids emitting redundant diff
report messages unless the user provides the --redundant switch.

	* tools/abipkgdiff.cc (options::show_redundant_changes): New data
	member.
	(options::options): Initialize it.
	(display_usage): Add a help string for the --redundant command
	Line option.
	(set_diff_context_from_opts): New static function.
	(compare): Take the options variable.  Set the diff context from
	the options, especially if we should show redundant changes or
	not.  Use that diff context when comparing ABIs.
	(parse_command_line): Parse the new --redundant command line
	switch.
	* doc/manuals/abipkgdiff.rst: Document the new --redundant option.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:11:20 +02:00
Dodji Seketeli
71a5e0762e Support comparing only shared libraries
It turned out on some packages we are interested on comparing shared
libraries only.  This patch adds that functionality by adding a new
--dso-only command line option to abipkgdiff.

	* tools/abipkgdiff.cc (options::compare_dso_only): New data
	member.
	(options::options): Initialize it.
	(display_usage): Display a little help string for it.
	(create_maps_of_package_content): Take the option variable.  Do
	not compare non-dso files if the --dso-only option was provided.
	(extract_package_and_map_its_content, prepare_packages, compare):
	Take the option variable.
	(parse_command_line): Parse the new --dso-only option.
	* doc/manuals/abipkgdiff.rst: Add documentation for the new
	--dso-only option.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:11:15 +02:00
Dodji Seketeli
2da9825c59 Comment functions and types of abipkgdiff
* src/abg-dwarf-reader.cc (get_soname_of_elf_file): Better wording
	of the apidoc of this function.
	* tools/abipkgdiff.cc (verbose, elf_file_paths): Add apidoc for
	these global variables.
	(struct options, ): Add apidoc for these types.
	(options::{erase_extraction_directory,
	erase_extraction_directories}, display_usage, extract_rpm)
	(erase_created_temporary_directories, extract_package)
	(file_tree_walker_callback_fn, compare)
	(create_maps_of_package_content)
	(extract_package_and_map_its_content, prepare_packages, compare)
	(parse_command_line): Add apidoc for these functions.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:11:08 +02:00
Dodji Seketeli
21bf2a87d8 Comment functions and types of abipkgdiff
* src/abg-dwarf-reader.cc (get_soname_of_elf_file): Better wording
	of the apidoc of this function.
	* tools/abipkgdiff.cc (verbose, elf_file_paths): Add apidoc for
	these global variables.
	(struct options, ): Add apidoc for these types.
	(options::{erase_extraction_directory,
	erase_extraction_directories}, display_usage, extract_rpm)
	(erase_created_temporary_directories, extract_package)
	(file_tree_walker_callback_fn, compare)
	(create_maps_of_package_content)
	(extract_package_and_map_its_content, prepare_packages, compare)
	(parse_command_line): Add apidoc for these functions.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:10:07 +02:00
Dodji Seketeli
080218e6a1 Various style fixes
* abipkgdiff.cc (get_soname_of_elf_file): Fix spacing.
	* tools/abipkgdiff.cc (elf_file_paths): Make this global variable
	static.
	(extract_rpm): Rename parameter pkg_path name into package_path.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:10:03 +02:00
Dodji Seketeli
5df40e91ce Remove the last direct fiddling with ELF from abipkgdiff.cc
Directly using elfutils from abipkgdiff.cc feels like a taping into
the wrong abstraction layer from this level.  So this patch moves the
determination of the type of elf file into abg-dwarf-reader.cc and
uses it from there.  The patch also simplifies the instantiation of
types elf_file and package, from abipkgdiff.cc.

	* abg-dwarf-reader.h (enum elf_type): Move this declaration here
	from abipkgdiff.cc to here.
	(get_type_of_elf_file): Declare this new function.
	(get_soname_from_elf): Change this to take a path to the elf file
	rather than a Elf* handler.  So now to use this, the user doesn't
	have to get her hand dirty with elfutils.
	* src/abg-dwarf-reader.cc (get_soname_from_elf): Change this to
	take a path to the elf file rather than a Elf* handler.
	(elf_file_type): Move this static function here, from
	abipkgdiff.cc.
	(get_type_of_elf_file): New function.  This has been factorized
	out of create_maps_of_package_content() in abipkgdiff.cc.
	* tools/abipkgdiff.cc (class elf_file): Changed struct elf_file
	into this.  Make the default constructor private.
	(elf_file::elf_file): Change the constructor to just take the path
	to the elf_file.  The base name, soname and elf file type are now
	computed from the path file, in the constructor.  This makes
	instantiation much much easier from the point of view of the user
	of the type.
	(struct abi_diff): Renamed struct abi_changes into this.
	(abi_diff::has_changes): Define new member function.
	(abi_diffs): Remove this global variable.
	(package::package): Remove the elf file type from the set of
	parameters of this constructor.  Rather, compute that elf file
	type from the path to the elf file, in the constructor.  Again,
	this eases the use of the type.
	(elf_file_type): Remove this from here, as it got moved to
	abg-dwarf-reader.cc.
	(compare): In the elf_file overload, return true if the comparison
	yields ABI changes.
	(create_maps_of_package_content): Do not fiddle with elfutils
	stuff here.  Rather, just instantiate elf_file and the analyzing
	of the file magically happens.
	(compare): Make the package overload take an abi_diff as output
	parameter, rather than populating a global variable in return.
	(compare): Add an other overload for package that doesn't take the
	abi_diff as output parameter and write it in terms of the previous
	one.
	(main): Adjust as the instantiation of package is now simpler.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:09:57 +02:00
Dodji Seketeli
e96f9f3690 Add a --verbose option to abipkgdiff
It turned out it's important to be able to see what abipkgdiff is
actually doing.  This patch adds a --verbose option that emits many
useful information about the tool's progress.

	* tools/abipkgdiff.cc (verbose): Add a new global variable.
	(package::erase_extraction_directory, extract_rpm, compare)
	(create_maps_of_package_content): Emit verbose information.
	(parse_command_line): Parse the --verbose option.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:09:53 +02:00
Dodji Seketeli
3aa51dac47 Use the library to implement ABI comparison in abipkgdiff
Until now, abipkgdiff was spawning a process running the 'abidiff'
command line tool to perform ABI comparison on binaries.  This helped
in sketching what was possible with this tool.  However, it's
sub-optimal in a final setup so this patch uses the libabigail library
to perform that comparison.

	* tools/abipkgdiff.cc (compare): In the overload for elf_file, use
	abigail::comparison::compute_diff() to compare the ABI of two
	corpora.  The corpora themselves is read using
	abigail::dwarf_reader::read_corpus_from_elf().  This cleans up the
	output of the tool because nothing is emitted to standard output
	if the two ABI corpora compares equal.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:09:43 +02:00
Dodji Seketeli
2c3677bcfa Fix several string passing issues in abipkgdiff.cc
A number of functions have string parameters passed by value.  Ooops.
They must be passed by reference.

Fixed thus.

	* tools/abipkgdiff.cc (elf_file::elf_file): Pass the strings by
	reference.  Also, change the order of the parameters; all the
	strings are passed first, then the elf_type is passed last.
	(package::package): Likewise, pass the strings by reference, not
	by value.
	(create_maps_of_package_content): Adjust for the change in
	parameters order of elf_file::elf_file.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:09:36 +02:00
Dodji Seketeli
63ffa0320a Only try to compare DSOs or executable binaries in abipkgdiff
* tools/abipkgdiff.cc (compare): In the overload for packages,
	only compare binaries that are DSO or executable.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:09:14 +02:00
Dodji Seketeli
e6dc360038 Avoid flushing the output stream in abipkgdiff.cc
* tools/abipkgdiff.cc (extract_package)
	(create_maps_of_package_content, compare, main): Avoid flushing
	the output stream arbitrarily.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:09:06 +02:00
Sinny Kumari
254dfd3655 Move get_soname() function to abg-dwarf-reader.h/cc
Initially, fetching SONAME from a given DSO file was done in
abipkgdiff.cc. But, this function fits better when defined in
abg-dwarf-reader.cc in order to make it usable by other tools if
needed. For consistancy, get_soname() function has been renamed to
get_soname_from_elf().

        * include/abg-dwarf-reader.h (get_soname_from_elf): Declare
         new function
        * src/abg-dwarf-reader.cc (get_soname_from_elf): Define new
        function
        * tools/abipkgdiff.cc (get_soname): Remove function
        (pkg_diff): Call get_soname_from_elf() instead of get_soname()

Signed-off-by: Sinny Kumari <sinny@redhat.com>
2015-07-17 10:09:06 +02:00
Dodji Seketeli
e0b4f2b7e2 Important organizational changes in abipkgdiff.cc
This patch introduces many changes that should hopefully improve
legibility and ease of maintenance.  Here is a list of the topic of
the changes:

  * Avoid using shortened names when the line is not too long.

  * Use shared_ptr when possible.

  * When a function parameter is not meant to be nil, do not pass it
    as a pointer; rather, pass it as a reference.

  * Avoid doing things that can "fail" in a destructor; e.g, spawning
    a process.  Also, it's not common practise to cleanup a resource in a
    type destructor, when that resource has not been created in one of the
    member functions of the type.  It eases maintenance when resource
    creation and cleanup is performed at the same logical level.

	* tools/abipkgdiff.cc (option::package{1,2}): Rename
	option::pkg{1,2} into this, to increase legibility.
	(option::debug_package{1,2}): Likewise, rename
	option::debug_pkg{1,2} into this.
	(elf_file::~elf_file): Do not "delete this" in a destructor.  This
	leads to double free.  It's when someone invokes the "delete"
	operator on a pointer to the object that the destructor of the
	object is executed automatically; so if in the destructor the
	delete operator is called again, bad things are going to happen.
	As the destructor is now empty, remove it altogether.
	(elf_file_sptr): New typedef for shared_ptr<elf_file>.
	(package::path): Rename package::pkg_path into this, for better
	legibility.
	(package::extracted_package_dir_path): Rename
	package::extracted_pkg_dir_path into this.
	(package::type): Rename package::pkg_type into this.
	(package::is_debug_info): Rename package::is_debuginfo_pkg into
	this.
	(package::path_elf_file_sptr_map): Rename
	package::dir_elf_files_map into this because this is a map of
	path -> elf_file_sptr.  Also, now the value of the map element is
	a elf_file_sptr, no more an elf_file*.
	(package::debug_info_package): Rename package::debuginfo_pkg into
	this.
	(package::package): Adjust for the changes above.
	(package::{erase_extraction_directory,
	erase_extraction_directories}): New member functions.
	(elf_file_paths): Renamed dir_elf_files_path into this.
	(erase_created_temporary_directories)
	(create_maps_of_package_content)
	(extract_package_and_map_its_content, prepare_packages): New
	static functions.
	(get_soname, elf_file_type, extract_rpm): Make this static.
	(extract_package): Take a const package& rather than a
	package_sptr to express that the function really expects a non-nil
	object by reference (not by copy) and that the object won't be
	modified.  Using a reference removes the possibility that the
	pointer could be nil, causing crashes in the code where
	parameter->something was used.  Now only parameter.something can
	be used, so no crash possible there.  This is more solid code.
	(file_tree_walker_callback_fn): Rename callback() into this.  It
	makes the code more legible and kind of 'self-documented'.  At
	least you get the hint that this is a callback function for some
	file tree walking (ftw) function. Adjust for the relevant names
	renaming above.
	(compare): Rename compute_abidiff into this; again, this increases
	legibility; at least at the point of use of this function.  Rename
	compare_package() into a an overload of compare() as well.
	compare_package() used to take a vector of packages.  It was hard
	to guess by reading the signature of the function, which element
	of the vector is expected to be the first vector of the
	comparison, which one is to be the second, etc.  Now, this
	function takes two packages, named first_package and
	second_package.  That is more "typed"; that is, the signature is
	more meaningful.  Greater legibility, hopefully.  And in the body
	of the function, the debug information packages are now accessed
	using the package::debug_info_package data member.  Again, this is
	less surprising, I believe.  Also, explicitly erase the temporary
	files that were created during this comparison.  All this
	simplifies the logic of this function, hopefully.
	(parse_command_line): Make this static.  Add new --d1 and --d2
	command line switches that are shortcuts of --debug-info-pkg1 and
	--debug-info-pkg2.  Adjust this function for the relevant name
	changes above.  Make lines be shorter than 80 characters.
	(main): Do not create any vector of parameters anymore as the
	compare_packages() function don't take any vector of parameter
	anymore.  Just instantiate first_package and second_package now.
	Adjust for the relevant name changes above.  This hopefully
	simplifies the logic of this function.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:08:56 +02:00
Dodji Seketeli
c53994326e Wording fixes in abipkgdiff.cc
Through the libabigail project, we try to:
 1/ make function names start with a verb
 2/ avoid shortening function names, *unless* longer names make the
 current line exceed 80 characters per line.

We believe these rules improve legibility for people reading the code.

This patch slightly changes abipkgdiff.cc file to comply with the
above.

	* tools/abipkgdiff.cc (extract_package): Renamed extract_pkg into
	this because shortening 'package' into 'pkg' provides no
	legibility improvement.
	(compare_packages): Renamed pkg_diff() into this, so that the name
	of the function starts with a verb, and the shortened 'pkg' word
	is renamed back to the 'package' word.  This way, the code almost
	reads like normal English sentences with verbs and complement,
	thus enhancing legibility and easing latter maintenance.
	(main): Adjust for the changes above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:08:42 +02:00
Dodji Seketeli
039db6cbfe Re-indent tools/abipkgdiff.cc
While reading the source code, I realized parts of it where not yet
following the GNU-style indentation of the rest of the project files.

So I thought I'd do this early now, so that other changes happen on
top of the properly indented file.

Fixed thus.

	* tools/abipkgdiff.cc: Re-indent the file properly and fix some
	white spacing here and there.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:08:34 +02:00
Dodji Seketeli
397aaea630 Some slight typo and wording fixes in abipkgdiff
* tools/abipkgdiff.cc (display_usage): Fixed the typo in
	'bi-pacakge.'  Also, refer to 'package', not to 'bi-package' that
	is surprising to the user at first.
	(compute_abidiff): Shorten the size of the introductory line.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:08:26 +02:00
Dodji Seketeli
61f499f5a5 Remove names of unused variables in callback()
The compiler complains that in function callback(), parameters st and
flag are unused.  In that case, C++ allows the name of the parameter
to be omitted; that makes the compiler complaint go away.

	* tools/abipkgdiff.cc (callback): Remove the name of parameters st
	and flag.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:08:19 +02:00
Dodji Seketeli
fc805d43b5 Remove useless const from the declaration of extract_rpm()
In this declaration:

    const bool
    extract_rpm(const string& pkg_path, const string &extracted_pkg_dir_path)

the compiler rightfully complains that the const qualifier on the
return type is useless.  This is because the value is returned by copy
so the const-ness is not relevant.

Fixed thus.

	* tools/abipkgdiff.cc (extract_rpm): Remove useless const qualifier.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:08:06 +02:00
Dodji Seketeli
9d25aa0125 End all branches of get_soname() finish with a return statement
The compiler complains that there are some branches in the
get_soname() function that don't end up with a return statement.  For
instance, there is no return statement right before the end of the
function, in case the outermost for loop is not taken.

This patch fixes that by having just one return statement at the end
of the function.

	* tools/abipkgdiff.cc (get_soname): Have just one return statement
	at the end of this function.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:07:56 +02:00
Dodji Seketeli
ab548d0086 Fix abipkgdiff compilation issues
The compiler rightfully complains that data members should be
initialized in the other in which they are declared.

Fixed thus.

	* tools/abipkgdiff.cc (elf_file::elf_file): Initialize data member
	in the same order as they were declared.
	(package::package): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-17 10:07:37 +02:00
Sinny Kumari
29b3c26a8d Exclude processing symlink, display removed/added binaries between two packages
Removed binaries can also lead to ABI breakage if an applicating was using
it previously. So, display it in ABI change report. Also, looking for
ABI change in symbolic link files doesn't make sense. Now, we are not
looking into ABI changes in symlink binaries.

	* tools/abipkgdiff.cc (abi_changes): Declare new struct
	(callback): Exclude symbloic link file for durther processing
	(compute_abidiff): Consider SONAME if exists as key in map instead
	of binary name, else binary as key. Also, print if removed/added
	binaries exist between packages
2015-07-17 10:07:37 +02:00
Sinny Kumari
4d9bd0a155 Stdout ABI changes if same binary found in both package
Now, abipkgdiff can take two rpm packages and optional corresponding
debug-info pacakges. It look for same binary in both rpm directory and
if found calls abdiff along with debug-info options to get ABI changes
between them.

	* tools/abipkgdiff.cc (compute_abidiff): New function
	tools/abipkgdiff.cc (pkg_diff): Iterate through list of binaries
	in both package directory and call compute_diff function if
	same binary found in both file.
	tools/abipkgdiff.cc (main): Also consider debug-info directories
	avilable in debu-info packages.

Signed-off-by: Sinny Kumari <sinny@redhat.com>
2015-07-17 10:07:37 +02:00
Sinny Kumari
3789a29caf Save ELF files, their type and SONAME if exist for extracted packages
An RPM package may conatins binaries, source/header files, config files,
etc. For abi check we are interested only in ELF binary files. This commit
stores binary files from extracted RPM in a map whose key is
binary file basename and value is struct elf_file with memeber variable
name, path, soname, type

	* tools/abipkgdiff.cc (elf_type): Declare new enum
	(elf_file): Declare new struct
	(package): Add member variable dir_elf_files_map
	(get_soname): Define new function
	(elf_file_type): Define new function
	(extract_rpm): Iterate over extracted directory files
	and filter ELF binary files along with their information
	like name, soname, elf_type and save in dir_elf_files_map
2015-07-17 10:07:37 +02:00
Sinny Kumari
b708412e92 Extract packages(RPMs) into temporary directories for further processing
Input pacakges need to extracted for further processing which includes
fecthing all files in extracted rpms and look for ELF files aginst
which abi diff is required. Pacakges will be extracted in system tmp
directory.

	* tools/abipkgdiff.cc (struct package): Declare new struct
	(package_sptr): Declare shared_ptr for struct package
	(extract_rpm): Define new fuction to extract rpm package
	(extract_pkg): Define new function to extract pacakge
	(pkg_diff): Define new function to get ABI diff between
	two packages
	(main): Create new object of type pacakge for each binary
	and debuginfo pacakge passed in commandline options

Signed-off-by: Sinny Kumari <sinny@redhat.com>
2015-07-17 10:07:37 +02:00
Sinny Kumari
b55e516d49 Guess RPM file type
To run abipkgdiff between two pacakges, it should know whether
input files are valid pacakge file or not. This patch detects RPM and SRPM
pacakge file type. abipkgdiff uses it to know whether input files are
valid RPM pacakge file or not.

	* include/abg-tools-utils.h (file_type): Added member
	FILE_TYPE_RPM and FILE_TYPE_SRPM
	(operator<<): New function declaration.
	* src/abg-tools-utils.cc (file_type): Detect RPM and
	SRPM file type
	(operator<<): New function definition
	* tools/abidiff.cc (main): Check for RPM and SRPM
	file type as well.
	* tools/abilint.cci (main): Check for RPM and SRPM file
	type as well.
	* tools/abipkgdiff.cc (main): Check whether input files
	to abipkgdiff are valid RPM files or not.

Signed-off-by: Sinny Kumari <sinny@redhat.com>
2015-07-17 10:07:37 +02:00
Sinny Kumari
411b60c30d Initial skeleton of abipkgdiff tool
Motive of abipkgdiff tool is to provide abi changes between two
pacakges. Packages can be .rpm, .deb or archives. It also takes
optional debug-info package to support pacakges shipping separate
debug-info.

This commit set-up initial skeleton of abipkgdif tool consisting of
help and usage otions. It ensures pkgdiff tool compiles and run when
libabigail gets compiled as whole. Initially, we will add support for
ABI changes for two rpm packages. Further, support for other pacakging
format can be added.

	* tools/Makefile.am: Include abipkgdiff.cc in compilation and
	generate abipkgdiff binary.
	* tools/abipkgdiff.cc: New file

Signed-off-by: Sinny Kumari <sinny@redhat.com>
2015-07-17 10:07:37 +02:00
Dodji Seketeli
5b09ea77e2 Handle the life time of the map of canonical types
While working on something else, it turned out that we need to cleanup
(de-allocate) the map of canonical types when all the translation
units that own types are de-allocated.  Otherwise, when new
translation units are created later, the types in the canonical types
map become unrelated to the types in these new translation units,
leading to memory management issues.

This patch introduces a "usage watchdog" which detects when no
translation unit uses the type system anymore.  That usage watchdog is
then used in the destructor of the translation_unit type to
de-allocate the global data that is logically owned by by the type
system.

The patch also changes the API to read translation units and corpora
in a way that forces users to get a handle on the resulting shared
pointer.

	* include/abg-ir.h (type_base::canonical_types_map_type): Move
	this typedef into abg-ir.cc and out of the type_base namespace.
	(type_base::get_canonical_types_map): Likewise.
	* src/abg-ir.cc (canonical_types_map_type): New typedef that got
	moved here from type_base::canonical_types_map_type.
	(get_canonical_types_map): Likewise got moved here from
	type_base::get_canonical_types_map.  Made static in the process.
	(class usage_watchdog): New type.
	(usage_watchdog_sptr, usage_watchdog_wptr): New typedefs.
	(get_usage_watchdog, get_usage_watchdog_wptr, ref_usage_watchdog)
	(maybe_cleanup_type_system_data): New static functions.
	(translation_unit::priv::usage_watchdog_): Add new data member.
	(translation_unit::priv::priv): Get a reference on the usage
	watchdog.
	(translation_unit::priv::~priv): If the usage watchdog says that
	the type system is not used, then cleanup the global data
	logically owned by the type system.

	* include/abg-dwarf-reader.h (read_corpus_from_elf): Make this
	return a corpus and set the status by reference using a parameter.
	* src/abg-dwarf-reader.cc (read_corpus_from_elf): Implement the
	above.
	* include/abg-reader.h (read_translation_unit_from_file)
	(read_translation_unit_from_buffer)
	(read_translation_unit_from_istream): Remove the overloads that do
	not return a translation_unit_sptr and that pass it as a
	parameter.  Only keep the overloads that return a
	translation_unit_sptr, forcing users of the API to own a proper
	reference on the resulting translation_unit pointer.  That is
	important to handle the life time of the global data of the type
	system that need to be cleared when the last translation unit is
	de-allocated.
	* src/abg-reader.cc (read_translation_unit_from_input): Make this
	return a translation_unit_sptr.
	(read_translation_unit_from_file)
	(read_translation_unit_from_buffer)
	(read_translation_unit_from_istream): Remove the overloads that do
	not return a translation_unit_sptr and that pass it as a
	parameter.  Only keep the overloads that return a
	translation_unit_sptr.
	(read_to_translation_unit): Make this return a
	translation_unit_sptr.
	* tests/print-diff-tree.cc (main): Adjust.
	* tests/test-diff-dwarf.cc (main): Likewise.
	* tests/test-ir-walker.cc (main): Likewise.
	* tests/test-read-dwarf.cc (main): Likewise.
	* tests/test-read-write.cc (main): Likewise.
	* tools/abicompat.cc (main): Likewise.
	* tools/abidiff.cc (main): Likewise.
	* tools/abidw.cc (main): Likewise.
	* tools/abilint.cc (main): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-09 11:12:40 +02:00
Dodji Seketeli
f87d179a01 Add --d{1,2} shortcut options for --debug-info-dir{1,2} in abidiff
It turned out typing --debug-info-dir{1,2} is a tad cumbersome.  So this
patch adds --d1 and --d2 shortcut for these options.

	* tools/abidiff.cc (display_usage): Add the --d{1,2} to the help
	strings.
	(parse_command_line): Parse the new --d1 and --d2 options.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-09 11:11:16 +02:00
Dodji Seketeli
a2601a596a Factorize incompatible and subtype changes detection
In abg-comparison.h, there is no function to test if a given
corpus_diff carries incompatible or subtype (after having applied
suppression specifications) ABI changes.  So this patch factorizes the
code of abidiff.cc to provide these features to corpus_diff.

	* include/abg-comparison.h (corpus_diff::{has_incompatible_changes,
	has_net_subtype_changes}): Declare new member functions.
	* src/abg-comparison.cc (corpus_diff::{has_incompatible_changes,
	has_net_subtype_changes}): Define them.
	* abidiff.cc (main): Use the new member functions above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-09 11:10:24 +02:00
Dodji Seketeli
bfeec954c6 Add a --suppr short alias to the --suppressions option of abidiff
* tools/abidiff.cc (display_usage): Add a help string for the new
	--suppr option.
	(parse_command_line): Support the --suppr option which is an alias
	for --suppressions.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-06-23 13:17:37 +02:00
Dodji Seketeli
6c1e7da30d Bug 18580 - abidw ignores --out-file
So I forgot to finish the implementation of the --out-file option.
This patchlet addresses that.

	* tools/abidw.cc (main): Take the argument of --out-file into
	account when emitting the serialized form of the ABI.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-06-23 01:15:01 +02:00
Dodji Seketeli
96eb3a5698 Build libabigail tools as position-independent code
It turned out the hardened Rawhide build is failing if I don't this.

	* tools/Makefile.am: Compile the binaries here with -fPIC.  Note
	that the library libabigail.la is built with libtool which already
	takes care of this, so no need to worry about this for
	libabigail.la.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-06-07 16:55:29 +02:00
Dodji Seketeli
41d0ad035f Fix symbols comparison
While working on something else, I noticed that the code for handling
copying symbols (and their aliases) was broken, and so comparing two
symbols which main name were different by which had aliases that were
equal was wrongly resulting in the two symbol being different. I think
we shouldn't actually copy symbols and their aliases.  Once a symbol
is allocated, interested code should just manipulate that symbol by
address rather than by value an thus do away with the copying.

The patch does that, essentially.  In the implementation of a symbol,
the aliases as well as the main symbol are now weak pointers, rather
than naked pointers.  Numerous API entry points that were taking
containers of elf_symbol (and were copying elf_symbols over) are not
taking containers of smart pointers to elf_symbol.  Copying of
instances of elf_symbol is now thus disabled.

As a result many tests that were exercising elf_symbols (with alias)
comparison have been updated.

As a result, many empty sub-result of PR libabigail/PR17948 are now
fixed.

	* include/abg-ir.h (elf_symbol_wptr): New typedef.
	(elf_symbol): Make the constructors and assignment operator
	private.  The type can neither be copied nor created with the new
	operator.
	(elf_symbol::create): New static member function.
	(elf_symbol::{get_main_symbol, get_next_alias, add_alias}):
	Adjust.
	( compute_aliases_for_elf_symbol): Likewise.
	(elf_symbol::operator=): Make this private.
	(elf_symbol::get_alias_which_equals): Declare new member function.
	* src/abg-comp-filter.cc (function_name_changed_but_not_symbol):
	Adjust.
	* src/abg-comparison.cc
	(class_diff::ensure_lookup_tables_populated): Adjust.
	* src/abg-corpus.cc
	(corpus::priv::build_unreferenced_symbols_tables): Likewise.
	* include/abg-dwarf-reader.h (lookup_symbol_from_elf)
	(lookup_public_function_symbol_from_elf): Adjust.
	* src/abg-dwarf-reader.cc (lookup_symbol_from_sysv_hash_tab)
	(lookup_symbol_from_gnu_hash_tab, lookup_symbol_from_elf_hash_tab)
	(lookup_symbol_from_symtab, lookup_symbol_from_elf)
	(lookup_public_function_symbol_from_elf)
	(lookup_public_variable_symbol_from_elf): Adjust.
	(read_context::lookup_elf_symbol_from_index): Likewise.
	(read_context::lookup_elf_fn_symbol_from_address): Likewise.
	(read_context::lookup_elf_var_symbol_from_address): Likewise.
	(read_context::lookup_public_function_symbol_from_elf): Likewise.
	(read_context::lookup_public_variable_symbol_from_elf): Likewise.
	(read_context::load_symbol_maps): Likewise.
	(build_var_decl, build_function_decl): Likewise.
	* src/abg-ir.cc (elf_symbol::priv::{main_symbol_, next_alias_}):
	Change the type of these from elf_symbol* to elf_symbol_wptr.
	(elf_symbol::priv::priv): Adjust.
	(elf_symbol::{create, get_alias_which_equals}): Define new functions.
	(textually_equals): Likewise.
	(elf_symbol::{get_main_symbol, is_main_symbol, get_next_alias,
	add_alias}): Adjust to return or take elf_symbol_sptr type, rather
	than a elf_symbol* one.
	(elf_symbol::{get_aliases_id_string, does_alias}): Adjust.
	(compute_alias_for_elf_symbol): Likewise.
	(elf_symbol::operator==): Two symbols A and B are now equal if A
	has at least one alias that is textually equal to B.
	(equals): In the overload for function_decls, in the part where we
	compare the decl_base part of the functions without considering
	their decl names, we now also omit considering their linkage
	names, because we compared they symbols before.
	* tools/abisym.cc (main): Adjust.
	* tests/data/test-diff-dwarf/test12-report.txt: Adjust.
	* tests/data/test-diff-dwarf/test12-report.txt: Adjust.
	* tests/data/test-diff-dwarf/test18-alias-sym-report-0.txt: Adjust.
	* tests/data/test-diff-dwarf/test8-report.txt: Adjust.
	* tests/data/test-diff-filter/test10-report.txt: Adjust.
	* tests/data/test-diff-filter/test13-report.txt: Adjust.
	* tests/data/test-diff-filter/test2-report.txt: Adjust.
	* tests/data/test-diff-filter/test20-inline-report-0.txt: Adjust.
	* tests/data/test-diff-filter/test20-inline-report-1.txt: Adjust.
	* tests/data/test-diff-filter/test9-report.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-06-02 00:07:02 +02:00
Dodji Seketeli
fc55e7f343 Make abidiff and abicompat return meaningful exit codes
As per https://sourceware.org/bugzilla/show_bug.cgi?id=18146, abidiff
the exit code of abidiff and abicompat is now a bit field that can be
inspected to know if the ABI change reported is incompatible for sure,
or if it needs user review of the output to decide.

This patch also updates the documentation.

	* doc/manuals/abicompat.rst: Update documentation for abicompat
	exit codes.
	* doc/manuals/abidiff.rst: Likewise for abidiff exit codes.
	* include/abg-tools-utils.h (enum abidiff_status): Declare new
	enum.
	(operator{|,&,|=}): Declare new operators for the new enum
	abidiff_status.
	(abidiff_status_has_error, abidiff_status_has_abi_change)
	(abidiff_status_has_incompatible_abi_change): Declare new
	functions.
	* src/abg-tools-utils.cc (operator{|,&,|=}): Define these new
	operators.
	(abidiff_status_has_error, abidiff_status_has_abi_change)
	(abidiff_status_has_incompatible_abi_change): Define new
	functions.
	* tests/test-diff-filter.cc (main): Adjust for the new exit code
	of abidiff.
	* tests/test-diff-suppr.cc (main): Likewise.
	* tests/test-abicompat.cc (main): Likewise.
	* tools/abicompat.cc (enum abicompat_status): Remove.
	(operator{|,&,|=}): Remove these operators for enum
	abicompat_status.
	(perform_compat_check_in_normal_mode)
	(perform_compat_check_in_weak_mode): Return abidiff_status instead
	of abicompat_status.  Adjust therefore.
	(main): Adjust to return abidiff_status now, instead of a just
	zero for all non-error cases.
	* tools/abidiff.cc (main): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-04-10 16:26:36 +02:00
Dodji Seketeli
a102a2f032 Add support for abicompat weak mode
This patch implements the weak mode of abicompat.  In this mode, just
the application and the new version of the library are provided.  The
types of functions and variables of the library that are consumed by
the application are compared to the types of the functions and
variables expected by the application.  The goal is to check if the
types of the declarations consumed by the application and provided by
the library are compatible with what the application expects.

The abicompat first gets the set of symbols undefined in the
application and exported by the library.  It then builds the set of
declarations exported by the library that have those symbols.  We call
these the set of declarations of the library that are consumed by the
application.

Note that the debug information for the application does not contain
the declarations of the functions/variables whose symbols are
undefined.  So we can not just read them to compare them to
declarations exported by the library.

But the *types* of the variables and the *sub-types* of the functions
whose symbols are undefined in the application are present in the
debug information of the application.

So in the weak mode, abicompat compare the *types* of the declarations
consumed by the application as expected by the application (described
by the debug information of the application) with the types of the
declarations exported by the library.

To do this a number of changes were necessary.

The patch builds a representation of all the types found in the
application's debug info.  Before that, only the types that are
reachable from exported declarations were represented.

The abidw tool got a new --load-all-types to test this new ability of
loading all types.

The patch also adds support for looking a type, not by name, but by
its internal representation.

In the comparison engine, function_type_diff is introduced to
represent changes between two function types.  For this, a new class
type_or_decl_base has been introduced in the IR.  It's now the base
class for both decl_base and type_base.  And abigail::comparison::diff
now takes two pointers of type_or_decl, not decl_base anymore.  So
function_type_diff can take two function_type now; not that a
function_type has no declaration so it doesn't inherit decl_base.  A
bunch of changes got made just to adjust to this modification.

A number of fixes were made too, to make this work, like adding
missing comparison operators, removing asserts that too strong, etc..

The patch also adjust the test suite as well as the documentation.

	* include/abg-fwd.h (class type_or_decl_base): Forward declare
	this.
	(is_decl, is_type, is_function_type, get_name, get_type_name)
	(get_function_type_name, get_pretty_representation)
	(lookup_function_type_in_corpus, lookup_type_in_translation_unit)
	(lookup_function_type_in_translation_unit)
	(synthesize_function_type_from_translation_unit)
	(hash_type_or_decl): New function declarations.
	* src/abg-corpus.cc (lookup_type_in_corpus)
	(lookup_function_type_in_corpus): Define new functions.
	* include/abg-ir.h
	(translation_unit::lookup_function_type_in_translation_unit):
	Declare new friend function.
	(class type_or_decl_base): Declare this.
	(operator==(const type_or_decl_base&, const type_or_decl_base&)):
	Declare new operator.
	(operator==(const type_or_decl_base_sptr&, const
	type_or_decl_base_sptr&)): Likewise.
	(class {decl_base, type_base}): Make these class inherit
	type_or_decl_base.
	(decl_base::get_member_scopes): New const overload.
	(bool operator==(const function_decl::parameter_sptr&,
	                 const function_decl::parameter_sptr&)): New operator.
	(function_type::get_parameters): Remove the non-const overload.
	(function_type::get_pretty_representation): Declare new member
	function.
	(method_type::get_pretty_representation): Likewise.
	* src/abg-ir.cc (bool operator==(const type_or_decl_base&, const
	type_or_decl_base&)): Define new equality operator.
	(bool operator==(const type_or_decl_base_sptr&, const
	type_or_decl_base_sptr&)): Likewise.
	(strip_typedef): Do not expect canonicalized types anymore.  Now
	the system accepts (and expects) canonicalized types in certain
	cases.  For instance, non-complete types and aggregated types that
	contain non-complete sub-types.
	(get_name, get_function_type_name, get_type_name)
	(get_pretty_representation, is_decl, is_type, is_function_type)
	(lookup_function_type_in_translation_unit)
	(synthesize_function_type_from_translation_unit)
	(lookup_type_in_scope, lookup_type_in_translation_unit): Define
	new functions or new overloads.
	(bool operator==(const function_decl::parameter_sptr&,
	                 const function_decl::parameter_sptr& r)): Define
	new operator.
	(function_type::get_parameters): Remove non-const overload.
	(function_type::get_pretty_representation): Define new function.
	(function_type::traverse): Adjust.
	(method_type::get_pretty_representation): Likewise.
	(function_decl::get_pretty_representation): Avoid emitting the
	type of cdtors.
	(hash_type_or_decl): Define new function.
	* include/abg-dwarf-reader.h (create_read_context)
	(read_corpus_from_elf): Take a new 'read_all_types' flag.
	* src/abg-dwarf-reader.cc (read_context::load_all_types_): New
	flag.
	(read_context::read_context): Initialize it.
	(read_context::canonical_types_scheduled): If some types still
	have non-canonicalized sub-types, then do not canonicalize them.
	(read_context::load_all_types): New member functions.
	(build_function_decl): Do not represent void return type like
	empty type anymore, rather, represent it like a void type node.
	(build_ir_node_from_die): When asked, load all types
	including those that are not reachable from an exported
	declaration.
	(create_read_context, read_corpus_from_elf): Take a new
	'load_all_types' flag and honour it.
	* src/abg-reader.cc (read_context::type_is_from_translation_unit):
	Support looking up function types in the current translation unit,
	now that we now how to lookup function types.
	* include/abg-comparison.h (diff_context::{has_diff_for, add_diff,
	set_canonical_diff_for, set_or_get_canonical_diff_for,
	get_canonical_diff_for}): Make these take instances of
	type_or_decl_base_sptr, instead of decl_base_sptr.
	(diff::diff): Likewise.
	(diff::{first_subject, second_subject}): Make these return
	type_or_decl_base_sptr instead of decl_base_sptr.
	(type_diff_base::type_diff_base): Make these take instances of
	type_or_decl_base_sptr instead of decl_base_sptr.
	(distinct_diff::distinct_diff): Likewise.
	(distinct_diff::{first, second}): Make these return
	type_or_decl_base_sptr instead of decl_base_sptr.
	(distinct_diff::entities_are_of_distinct_kinds): Make these take
	instances of type_or_decl_base_sptr instead of decl_base_sptr.
	(class function_type_diff): Create this new type.  It's a
	factorization of the function_decl_diff type.
	* src/abg-comparison.cc ():
	* src/abg-comp-filter.cc ({harmless, harmful}_filter::visit):
	Adjust as diff::{first,second}_subject() now returns a
	type_or_decl_base_sptr, no more a decl_base_sptr.
	(decls_type, decls_diff_map_type): Remove these typedefs and replace it with ...
	(types_or_decls_type, types_or_decls_diff_map_type): ... these.
	(struct {decls_hash, decls_equals): Remove these type sand replace them with ...
	(struct {types_or_decls_hash, types_or_decls_equals}): ... these.
	({type_suppression, variable_suppression}::suppresses_diff):
	Adjust.
	(diff_context::priv::decls_diff_map): Replace this with ...
	(diff_context::priv::types_or_decls_diff_map): ... this.
	(diff_context::{has_diff_for, add_diff, get_canonical_diff_for,
	set_canonical_diff_for, set_or_get_canonical_diff_for}): Take
	type_or_decl_base_sptr instead of decl_base_sptr.
	(diff::priv::{first, second}_subject): Make the type of these be
	type_or_decl_base_sptr, no more decl_base_sptr.
	(diff::priv::priv): Adjust for the subjects of the diff being of
	type type_or_decl_sptr now, no more decl_base_sptr.
	(diff_less_than_functor::operator()(const diff_sptr, const
	diff_sptr) const): Adjust.
	(diff::diff): djust for the subjects of the diff being of type
	type_or_decl_sptr now, no more decl_base_sptr.
	(diff::{first,second}_subject): Make the type of these be
	type_or_decl_base_sptr, no more decl_base_sptr.
	(report_size_and_alignment_changes): Likewise.
	(type_diff_base::type_diff_base): Make the type of this be
	type_or_decl_base_sptr instead of type_base_sptr.
	(distinct_diff::distinct_diff): Make this take instances of
	type_or_decl_base_sptr instead of decl_base_sptr.
	(distinct_diff::{first, second, entities_are_of_distinct_kinds}):
	Likewise.
	(distinct_diff::has_changes): Simplify logic.
	(distinct_diff::report): Adjust.
	(compute_diff_for_types): Add an additional case to support the
	new function_type.
	(report_size_and_alignment_changes): Make this take instances of
	type_or_decl_base_sptr instead of decl_base_sptr.
	(class_diff::priv::member_type_has_changed): Return an instance of
	type_or_decl_base_sptr rather than a decl_base_sptr.
	(class_diff::report): Adjust.
	(diff_comp::operator()(const diff&, diff&) const): Adjust.
	(enum function_decl_diff::priv::Flags): Remove.
	(function_decl_diff::priv::{first_fn_flags_, second_fn_flags_,
	fn_flags_changes_}): Remove.
	(function_decl_diff::priv::{fn_is_declared_inline_to_flag,
	fn_binding_to_flag}): Remove.
	(function_decl_diff::{deleted_parameter_at,
	inserted_parameter_at}): Remove.
	(function_decl_diff::ensure_lookup_tables_populated): Empty this.
	(function_decl_diff::chain_into_hierarchy): Adjust.
	(function_decl_diff::function_decl_diff): This now only takes the
	subjects.  It's body is now empty.
	(function_decl_diff::{return_type_diff, subtype_changed_parms,
	removed_parms, added_parms, type_diff}): Remove these member
	functions.
	(function_decl_diff::type_diff): Define new member function.
	(function_decl_diff::report): Simplify logic by using the
	reporting of the child type diff node.
	(compute_diff): Likewise, in the overload for function_decl_sptr
	simplify logic by using the child type diff object.
	(function_type_diff::priv): Define new type.
	(function_type_diff::{function_type_diff,
	ensure_lookup_tables_populated, deleted_parameter_at,
	inserted_parameter_at, finish_diff_type, first_function_type,
	second_function_type, return_type_diff, subtype_changed_parms,
	removed_parms, added_parms, get_pretty_representation,
	has_changes, has_local_changes, report, chain_into_hierarchy}):
	Define new functions.
	(compute_diff): Define new overload for function_type_sptr.
	* tools/abicompat.cc (options::weak_mode): New data member.
	(options::options): Initialize it.
	(enum abicompat_status): New enum
	(abicompat_status operator|(abicompat_status, abicompat_status))
	(abicompat_status& operator|=(abicompat_status &, abicompat_status))
	(abicompat_status operator&(abicompat_status, abicompat_status)):
	New operators to manipulate the abicompat_status enum.
	(display_usage): Add help string for the new --weak-mode option.
	(parse_command_line): Add the new --weak-mode command line
	argument.  If the tool is called with just the application and one
	library then assume that we are in the weak mode.
	(perform_compat_check_in_normal_mode): Define new function, factorized
	from what was in the main function.
	(perform_compat_check_in_weak_mode): Define new function.
	(struct {fn,var}_change): Define new types.
	(main): Use perform_compat_check_in_weak_mode() and
	perform_compat_check_in_normal_mode().
	* tools/abidiff.cc (main): Adjust.
	* tools/abidw.cc: (options::load_all_types): Add new data member.
	(options::options): Initialize it.
	(display_usage): New help string for --load-all-types.
	(parse_command_line): Support the new --load-all-types option.
	(main): Adjust and honour the --load-all-types option.
	* tools/abilint.cc (main): Adjust.
	* doc/manuals/abicompat.rst: Update documentation for the new weak
	mode.  Also provide stuff that was missing from the examples
	provided.
	* doc/manuals/abidw.rst: Update documentation for the new
	--load-all-types option.
	* tests/print-diff-tree.cc (main): Adjust.
	* tests/test-diff-dwarf.cc (main): Likewise.
	* tests/test-read-dwarf.cc (main): Likewise.
	* tests/data/test-abicompat/test0-fn-changed-app: Recompile this.
	* tests/data/test-abicompat/libtest5-fn-changed-libapp-v{0,1}.so:
	New new test input binaries
	* tests/data/test-abicompat/test5-fn-changed-app: Likewise.
	* tests/data/test-abicompat/test6-var-changed-app: Likewise.
	* tests/data/test-abicompat/libtest6-var-changed-libapp-v{0,1}.so:
	Likewise.
	* tests/data/test-abicompat/test5-fn-changed-report-0.txt:
	Reference output for one test above.
	* tests/data/test-abicompat/test6-var-changed-report-0.txt:
	Likewise.
	* tests/data/test-abicompat/test5-fn-changed-app.cc: Source file
	for a binary above.
	* tests/data/test-abicompat/test5-fn-changed-libapp-v{0,1}.{h,cc}:
	Likewise.
	* tests/data/test-abicompat/test6-var-changed-libapp-v{0,1}.{cc,h}:
	Likewise.
	* tests/data/test-abicompat/test6-var-changed-app.cc: Likewise.
	* tests/data/Makefile.am: Add the test related files above to the
	source distribution.
	* tests/test-abicompat.cc (in_out_spec): Add the new test input
	above to the list of inputs to feed to this test harness.
	(main): Support taking just the app and one library.
	* tests/data/test-read-dwarf/test{0, 1, 2.so, 3.so, 5.o,
	8-qualified-this-pointer.so,}.abi: Adjust for void type being
	really emitted now, as opposed to just being an empty type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-04-03 22:45:41 +02:00
Dodji Seketeli
705a6ae186 Add --no-architecture option to abidw
For portability of the regression tests of libabigail, we need abidw
to avoid emitting information about the architecture of the ELF file
it's looking at.  This patch thus adds a new --no-architecture option
to abidw for that purpose.

	* tools/abidw.cc (options::write_architecture): New flag.
	(options::options): Initialize it.
	(display_usage): Add usage string for the new --no-architecture
	option.
	(parse_command): Parse the new --no-architecture command line
	option.
	(main): Ignore the architecture name if required by the user.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-03-17 10:02:26 +01:00
Dodji Seketeli
dc2f054d03 Build the set of exported decls directly during DWARF loading
Until now, after the ABI corpus was built from DWARF, the translation
units of the corpus were walked and each function was considered for
addition into the set of exported decls.  During that walking, a first
version of the set was put into a std::list and then, a set of filters
(user-provided tunables like a list of regular expressions to keep or
remove some functions from the exported decls) is applied to that list
and the final set of exported decls is put in a std::vector.

Profiling has shown that this process of building the set of exported
decls is a hot spot and also that the current use of std::list was a
big memory consumer especially on binaries with large exported symbol
tables.

So this patch builds the set of exported decls "on the fly", during
DWARF reading, as opposed to waiting after the DWARF is read and
having to walk the corpus again.  The corpus defines a policy object
that encapsulates the methods for determining if a function or
variable ought to be part of the set of exported decls.  The DWARF
reader uses that policy object to determine which functions and
variables among those built during the reading ought be part of the
exported decls; the policy object also has a reference to the final
vector (managed by the corpus) that must hold the exported decls, so
the decls are put in that vector directly without unnecessary copying.

Profiling also showed that the string copying done by
{var_decl,function_decl}::get_id() was a hot spot.  So the patch
returns a reference there.

With this patch applied, the peak memory consumption of abidiff on
libabigail.so itself (abidiff libabigail.so libabigail.so) is 54MB of
resident and takes 2 minutes and 16s (on my slow system).  Without the
patch the peak consumption was more than 300MB and it was taking
slightly longer.

For the test of bug
https://sourceware.org/bugzilla/show_bug.cgi?id=17948, memory
consumtion and wall clock time spent is down from 3.4GB and 1m59s to
760MB and 0m43s.

	* include/abg-ir.h ({var,function}_decl::get_id): Return a
	reference.
	* src/abg-ir.cc ({var,function}_decl::get_id): Return a reference
	to the string rather than copying it over.
	* include/abg-corpus.h (class corpus::exported_decls_builder):
	Declare new type.
	(corpus::{sort_functions, sort_variables,
	maybe_drop_some_exported_decls, get_exported_decls_builder}):
	Declare new methods.
	* src/abg-corpus.h (corpus::exported_decls_builder::priv): Define
	new type.
	(class symtab_build_visitor_type): Remove this type that is
	useless now.
	(corpus::exported_decls_builder::{exported_decls_builder,
	exported_functions, exported_variables,
	maybe_add_fn_to_exported_fns, maybe_add_var_to_exported_vars}):
	Define new functions.
	(corpus::priv::is_public_decl_table_built): Remove this data
	member.  It's now useless.
	(corpus::priv::priv): Adjust.
	(corpus::priv::build_public_decl_table): Remove this member
	function.  It's now useless.
	(corpus::{priv::build_unreferenced_symbols_tables, get_functions,
	get_variables}): No need to build the public decls table here.
	It's already built by the time the corpus is read from DWARF now.
	(corpus::{sort_functions, sort_variables,
	maybe_drop_some_exported_decls, get_exported_decls_builder}):
	Define new member functions.
	* src/abg-dwarf-reader.cc (read_context::exported_decls_builder):
	New data member.
	(read_context::read_context): Initialize it.
	(read_context::{exported_decls_builder,
	maybe_add_fn_to_exported_fns, maybe_add_var_to_exported_vars}):
	Define new member functions.
	(read_debug_info_into_corpus): Get the the new
	'exported_decls_builder' object from the corpus and stick it into
	the read context so the DWARF reading code can use it to build the
	exported decls set.  When the DWARF reading is done, sort the set
	of exported functions and variables that was built.
	(build_ir_node_from_die): When a function or variable is built,
	consider putting it into the set of exported decls.
	* tools/abicompat.cc (main): Now that the exported decls is built
	*before* we had a chance to stick the list of symbol IDs to keep,
	call corpus::maybe_drop_some_exported_decls() to update the set of
	exported decls we should consider for the corpus.

was applied to that list and the final

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-02-24 13:15:10 +01:00
Dodji Seketeli
3b3dbf6643 Rename diff::length() into diff::has_changes()
Since it turned out that the length of the changes carried by a diff
node has never been used in the algorithms of the comparison engine,
the diff::length() feels wrong.  What we want is rather a name like
diff::has_changes() so this is what this patch does.

	* include/abg-comparison.h (*::has_changes): Rename the ::length()
	method of all the diff types that inherit the diff class into
	this, in the class declarations.
	* src/abg-comparison.cc (*::has_changes): Do the same as in the
	declarations, in the definitions.
	(diff::to_be_reported, distinct_diff::has_local_changes)
	(distinct_diff::report, distinct_diff::, array_diff::has_changes)
	(reference_diff::has_changes, qualified_type_diff::has_changes)
	(enum_diff::has_changes, translation_unit_diff::has_changes)
	(suppression_categorization_visitor::visit_end)
	(redundancy_marking_visitor::visit_begin): Adjust.
	* tests/test-diff-dwarf.cc (main): Adjust.
	* tools/abidiff.cc (main): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-02-05 12:44:59 +01:00
Dodji Seketeli
527d7ab218 Do not install the abinilint program
This program is meant to be used by libabigail developers to debug its
ini file parsing facilities.  So there is no need to install.

	* tools/Makefile.am: Add abinilint to the noinst_PROGRAMS primary.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-14 13:20:46 +01:00
Dodji Seketeli
b25f1bd7e7 Adjust archive-related code for the recent addition of tools_utils::*
What was in the abigail::tools namespace got recently moved in the
abigail::tools_unit namespace.  I forgot to adjust the client code
related to the archive support because that code is now compiled by
default on my main hacking box.  This patch fixes that.

	* tests/Makefile.am: tools/libtoolsutils.la is no more.
	* tests/test-write-read-archive.cc (main): Adjust.
	* tools/abiar.cc (extract_tus_from_archive): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-13 11:02:10 +01:00
Dodji Seketeli
322b0e7769 Expose a new libabigail::tools_utils namespace
The utilities present in this namespace were previously living in
tools/abg-tools-utils.h and tools/abg-tools-utils.cc.  They were not
exported and were meant to be useful to the tools writting in the
tools/ directory.  I realized that these utilities might be useful to
clients of the libabigail library in general so I am making them
available generally.  Note that the initial name of the namespace was
libabigail::tools; so renaming it to libabigail::tools_utils required
that I adjust some client code.  I have also cleaned up the code,
interfaces and their apidoc a little bit.

	* include/abg-tools-utils.h: Moved tools/abg-tools-utils.h in
	here.  Renamed the namespace tools into tools_utils.  Inject
	std::ostream, std::istream, std::ifstream, and std::string types
	into the tools_utils namespace.  Adjust the function declarations
	accordingly.  Remove the useless dirname() function declaration.
	* include/Makefile.am: Add abg-tools-utils.h to the list of
	exported headers.
	* src/abg-tools-utils.cc: Moved tools/abg-tools-utils.cc in here.
	Renamed the namespace tools into tools_utils.
	(get_stat): Add apidoc.
	(is_dir): Cleanup apidoc.
	(dir_name); Cleanup parameter name.
	(guess_file_type): Cleanup parameter type.
	* src/Makefile.am: Add abg-tools-utils.cc to the list of exported
	headers.
	* tools/Makefile.am: Do not build the temporary library
	libtoolsutils.la anymore as abg-tools-utils.{h,cc} have moved out
	of this directory.
	* tools/abicompat.cc (parse_command_line, main): Adjust for tools
	-> tools_utils namespace change.
	* tools/abidiff.cc (parse_command_line, main): Likewise.
	* tools/abidw.cc (parse_command_line, main): Likewise.
	* tools/abilint.cc (parse_command_line, main): Likewise.
	* tests/test-abicompat.cc (main): Adjust for tools -> tools_utils
	namespace change.
	* tests/test-abidiff.cc (main): Likewise.
	* tests/test-alt-dwarf-file.cc (main): Likewise.
	* tests/test-core-diff.cc (main): Likewise.
	* tests/test-diff-dwarf.cc (main): Likewise.
	* tests/test-diff-filter.cc (main): Likewise.
	* tests/test-diff-suppr.cc (main): Likewise.
	* tests/test-lookup-syms.cc (main): Likewise.
	* tests/test-read-dwarf.cc (main): Likewise.
	* tests/test-read-write.cc (main): Likewise.
	* tests/Makefile.am: Do not reference the libtoolsutils.la private
	library anymore.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-08 12:28:14 +01:00
Dodji Seketeli
76837d1cbf Update copyright years
* include/abg-comp-filter.h: Update copyright years.
	* include/abg-comparison.h: Likewise.
	* include/abg-config.h: Likewise.
	* include/abg-corpus.h: Likewise.
	* include/abg-diff-utils.h: Likewise.
	* include/abg-dwarf-reader.h: Likewise.
	* include/abg-fwd.h: Likewise.
	* include/abg-hash.h: Likewise.
	* include/abg-ini.h: Likewise.
	* include/abg-ir.h: Likewise.
	* include/abg-libxml-utils.h: Likewise.
	* include/abg-libzip-utils.h: Likewise.
	* include/abg-reader.h: Likewise.
	* include/abg-sptr-utils.h: Likewise.
	* include/abg-traverse.h: Likewise.
	* include/abg-viz-common.h: Likewise.
	* include/abg-viz-dot.h: Likewise.
	* include/abg-viz-svg.h: Likewise.
	* include/abg-writer.h: Likewise.
	* src/abg-comp-filter.cc: Likewise.
	* src/abg-comparison.cc: Likewise.
	* src/abg-config.cc: Likewise.
	* src/abg-corpus.cc: Likewise.
	* src/abg-diff-utils.cc: Likewise.
	* src/abg-dwarf-reader.cc: Likewise.
	* src/abg-hash.cc: Likewise.
	* src/abg-ini.cc: Likewise.
	* src/abg-ir.cc: Likewise.
	* src/abg-libxml-utils.cc: Likewise.
	* src/abg-libzip-utils.cc: Likewise.
	* src/abg-reader.cc: Likewise.
	* src/abg-traverse.cc: Likewise.
	* src/abg-viz-common.cc: Likewise.
	* src/abg-viz-dot.cc: Likewise.
	* src/abg-viz-svg.cc: Likewise.
	* src/abg-writer.cc: Likewise.
	* tests/print-diff-tree.cc: Likewise.
	* tests/test-abidiff.cc: Likewise.
	* tests/test-alt-dwarf-file.cc: Likewise.
	* tests/test-core-diff.cc: Likewise.
	* tests/test-diff-dwarf.cc: Likewise.
	* tests/test-diff-filter.cc: Likewise.
	* tests/test-diff-suppr.cc: Likewise.
	* tests/test-diff2.cc: Likewise.
	* tests/test-ir-walker.cc: Likewise.
	* tests/test-lookup-syms.cc: Likewise.
	* tests/test-read-dwarf.cc: Likewise.
	* tests/test-read-write.cc: Likewise.
	* tests/test-utils.cc: Likewise.
	* tests/test-utils.h: Likewise.
	* tests/test-write-read-archive.cc: Likewise.
	* tools/abg-tools-utils.cc: Likewise.
	* tools/abg-tools-utils.h: Likewise.
	* tools/abiar.cc: Likewise.
	* tools/abidiff.cc: Likewise.
	* tools/abidw.cc: Likewise.
	* tools/abilint.cc: Likewise.
	* tools/abisym.cc: Likewise.
	* tools/binilint.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-07 17:52:10 +01:00
Dodji Seketeli
0e1d9f9892 Add a --dump-diff-tree to abidiff for debugging purposes
I have felt the need to emit a textual representation of the diff
nodes tree maintained by the comparison engine for changed functions
and variables.  This patch adds that functionality.

	* include/abg-comparison.h (enum visiting_kind): Add new
	DO_NOT_MARK_VISITED_NODES_AS_TRAVERSED enumerator.
	(diff_context::{default_output_stream, error_output_stream,
	dump_diff_tree}): Declare new accessors.
	(diff::end_traversing): Take a new boolean flag.
	(print_diff_tree): Add new overload for diff_sptr.
	* src/abg-comparison.cc
	(diff_context::priv::{default_output_stream_,
	error_output_stream_, dump_diff_tree_}): New data members.
	(priv::priv): Initialize them.
	(diff_context::{default_output_stream_, error_output_stream_,
	dump_diff_tree, dump_diff_tree}): Define new accessors.
	(diff::end_traversing): Take a new flag that control whether or
	not to mark the current diff node as having been traversed.
	(diff::traverse): Take in account the visiting kind carried by the
	visitor to determine if the visited node should be marked as being
	traversed.
	(corpus_diff::priv::maybe_dump_diff_tree): Define new member
	function.
	(corpus_diff::report): Call it.
	(diff_node_printer::visit): Pretty print the diff node just once.
	(print_diff_tree): Define a new overload for diff_sptr.
	* tools/abidiff.cc (options::dump_diff_tree): New data member.
	(options::options): Initialize it.
	(display_usage): Add a help string for the new --dump-diff-tree
	command line switch.
	(parse_command_line): Parse the new --dump-diff-tree command line
	switch.
	(set_diff_context_from_opts): Set the diff context according to
	the --dump-diff-tree presence.
	* doc/manuals/abidiff.rst: Add a bullet point for the new
	--dump-diff-tree command line switch.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-28 11:36:52 +01:00
Dodji Seketeli
c887ad69ba Make abidiff *NOT* show redundant changes by default
Now that we are handling redundant diff node marking (and reporting)
with more finesse, I guess we can enable redundant diff reporting
elision by default again.

	* tools/abidiff.cc (options::options): Initialize
	options::show_redundant_changes to false.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-26 18:45:07 +01:00
Dodji Seketeli
8f994b5e29 Temporarily disable redundant diff report elimination
So, this is all about problem report
https://sourceware.org/bugzilla/show_bug.cgi?id=17693.

When redundant diff node reporting is enabled and when a diff node
appears twice in a diff tree, we detect that and the second occurrence
of the diff node is flagged as being redundant.  Later at diff tree
node reporting time, the redundant diff node is not reported.

The problem is that diff nodes are canonicalized.  That is, when the
same change is present twice in a diff, the same diff node is going to
be present twice.  So flagging the second occurrence as being
redundant amounts as flagging the first occurrence as being redundant
too!  So at reporting time, the diff tree visitor that walks the diff
tree nodes will avoid reporting the two occurrences of diff tree nodes
altogether.  This is what happens in the example of the bug above.  I
am reproducing the example here for convenience:

So suppose we have a first version of a library named lib-v0.so which
is made of this C code:

    int add(int a, int b)
    {
    }

Then suppose that code was changed in a subsequent version of the
library named lib-v1.so, leading to the following code:

    int add(float a, float b)
    {
    }

So, the diff tree node for the 'add' function is going to have several
child diff tree nodes, among which, one that carries the change for
the first parameter (int a becoming float a) and the one carrying the
change for the second parameter (int b becoming float b).

The diff tree node for the second parameter is going to be same diff
tree node as the one for the first parameter because what counts is
the change in the *type* of the parameter.  Thus, the diff tree node
for the second parameter is going to be marked as being redundant; and
so is the first parameter.

So abidiff lib-v0.so lib-v1.so yields:

    Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added
    function
    Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

You can see that even the function 'add' is not mentioned in the
report.  This is because it has also been considered as being
redundant because of a phenomenon named 'propagation'.  The
redundant-ness of the children nodes of the diff tree node of the
'add' function is propagated to the diff tree node of the add function
itself because that add function diff tree node has no child but
redundant diff children nodes.  This categorization behaviour is
correct.

What is not correct is that only the second child node of the add
function diff tree node should have been marked redundant.

I am going to tackle this issue a bit later.  For now, I am
temporarily disabling redundancy categorization for diff tree nodes by
default.  Hence this patch.

With this patch, abidiff lib-v0.so lib-v1.so yields:

    Functions changes summary: 0 Removed, 1 Changed, 0 Added function
    Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

    1 function with some indirect sub-type change:

      [C]'function int add(int, int)' has some indirect sub-type changes:
	parameter 0 of type 'int' changed:
	  name changed from 'int' to 'float'
	parameter 1 of type 'int' changed:
	  name changed from 'int' to 'float'

Note how the change on the second parameter appears equal to the
change on the first.

	* src/abg-comparison.cc
	(diff_context::priv::priv): Show redundant changes by default.
	(categorize_redundancy): Do not categorize redundancy if the
	diff_context says that we shouldn't.
	* tools/abicompat.cc (options::show_redundant): New data member.
	(options::options): Initialize to true.
	(display_usage): Add new help string for new --no-redundant and
	--redundant options.
	(parse_command_line): Parse new --no-redundant and --redundant
	command line options.
	(main): Initialize the diff context with respect to the
	options::show_redundant property.
	* tools/abidiff.cc (options::options): Initialize the
	show_redundant_changes data member to true.
	(display_usage): Show new help string for the new --no-redundant
	command line option.
	(parse_command_line): Parse the new --no-redundant command line
	option.
	* tests/data/test-diff-filter/libtest23-redundant-fn-parm-change-v0.so:
	New test data input.
	* tests/data/test-diff-filter/libtest23-redundant-fn-parm-change-v1.so:
	Likewise.
	* tests/data/test-diff-filter/test23-redundant-fn-parm-change-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test23-redundant-fn-parm-change-v0.c:
	Source code for the first binary above.
	* tests/data/test-diff-filter/test23-redundant-fn-parm-change-v1.c:
	Source code for the second binary above.
	* tests/data/Makefile.am: Add the new test data input to source
	distribution.
	* tests/test-abicompat.cc (in_out_specs): Add --no-redundant to
	abicompat when we don't want it to show redundant diff reports.
	* test-diff-filter.cc (in_out_specs): Likewise for abidiff.
	* test-diff-suppr.cc (in_out_specs): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-10 19:19:57 +01:00
Dodji Seketeli
775cfcde0c Wire the soname check into abicompat
Now that the comparison engine knows how to take SONAMEs into account
during ABI abi comparison, it's feasible to make abicompat leverage
that capability.  This patch does just that.

	* include/abg-comparison.h (corpus_diff::soname_changed): Declare
	new member function.
	* src/abg-comparison.cc (corpus_diff::soname_changed): Define new
	member function.
	(corpus_diff::length): Use the new corpus_diff::soname_changed()
	method.
	* tests/data/test-abicompat/libtest4-soname-changed-v0.so: New
	test input data.
	* tests/data/test-abicompat/libtest4-soname-changed-v1.so:
	Likewise.
	* tests/data/test-abicompat/test4-soname-changed-app: Likewise.
	* tests/data/test-abicompat/test4-soname-changed-report-0.txt:
	Likewise.
	* tests/data/test-abicompat/test4-soname-changed-app.cc: Source
	code for one of the binaries above.
	* tests/data/test-abicompat/test4-soname-changed-v0.cc: Likewise.
	* tests/data/test-abicompat/test4-soname-changed-v1.cc: Likewise.
	* tests/test-abicompat.cc (in_out_specs): Add the new test input
	data to the list of input data to run this harness over.
	(main): Take the soname change in account to determine if the
	change is ABI incompatible.
	* tests/data/Makefile.am: Add the new test input data above to source
	distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-08 13:47:00 +01:00
Dodji Seketeli
ef7e71febf Initial implementation of the abicompat tool
Given an application A that links to a shared library L of version V
denoted L(V) and a subsequent version of that library denoted L(V+P),
the 'abicompat' tool tells the user if L(V+P) is still ABI compatible
with L(V+P).  And if it is not, abicompat gives a reports that shows
the differences between L(V) and L(V+P) that makes L(V+P)
ABI-incompatible with A.

The source code of this tool is in the tools/abicompat.cc source
file.  To support this new tool, this commit changes the comparison
engine to optionally avoid showing added symbols that were not
referenced by any debug info.  It changes the ABI corpus type to allow
the specification of a list of variables and functions symbols to keep
(and drop all other functions and variables which have other symbols
on the floor even before starting to compare the two libraries).

This is how the abicompat tool itself works.  It basically compares
L(V) and L(V+P) but it only looks at their exported functions and
variables which symbols are undefined in application A.  If the list
of exported and defined variables and functions of L(V) whose symbols
are undefined in A equals that of L(V+P) (including the sub-types of
these variables and functions) A is still compatible with L(V+P).
Otherwise, they might not be compatible depending on the kind of
differences that are found.

	* include/abg-comparison.h
	(diff_context::show_added_symbols_unreferenced_by_debug_info):
	Declare new accessors.
	(corpus_diff::{deleted_variables,
	deleted_unrefed_function_symbols,
	deleted_unrefed_variable_symbols,
	apply_filters_and_suppressions_before_reporting}): Declare new
	methods.
	(corpus_diff::diff_stats): Declare this new type.  Actually this
	was previously corpus_diff::priv::diff_stats, which was a hidden
	internal type..  We are moving it here, in the external API so
	that client code can have more information about changes
	statistics.  Change all the previously publicly accessible data
	members into accessor functions.
	* src/abg-comparison.cc (class corpus_diff::diff_stats::priv): New
	type.
	(diff_context::priv::show_added_syms_unreferenced_by_di_): New
	data member.
	(diff_context::priv::priv): Adjust.
	(diff_context::show_added_symbols_unreferenced_by_debug_info):
	Define this new method.
	(corpus_diff::priv::emit_diff_stats):  Do not show the diff stat
	if the only changes is added function or variables symbols and if
	we were instructed to not show added symbols.
	(corpus_diff::priv::{diff_stats_, filters_and_suppr_applied_}):
	New data members.
	(corpus_diff::priv::priv): Initialize the
	filters_and_suppr_applied_ data member.
	(corpus_diff::priv::diff_stats): Move this type to
	corpus_diff::diff_stats.
	(corpus_diff::priv::{apply_filters_and_compute_diff_stats,
	emit_diff_stats}): Adjust.
	(corpus_diff::apply_filters_and_suppressions_before_reporting):
	Define new member function.
	(corpus_diff::report): Use the new
	apply_filters_and_suppressions_before_reporting() function, rather
	than applying the filters and suppressions by ourselves.  Also
	adjust to the use the accessors of the new corpus_diff::diff_stats
	type.
	(corpus_diff::{deleted_variables,
	deleted_unrefed_function_symbols,
	deleted_unrefed_variable_symbols}): Define new accessors.
	(corpus_diff::diff_stats::{diff_stats, num_func_removed,
	num_func_added, num_func_changed, num_func_filtered_out,
	net_num_func_changed, num_vars_removed, num_vars_added,
	num_vars_changed, num_vars_filtered_out, net_num_vars_changed,
	num_func_sym_removed, num_func_syms_added, num_var_syms_removed,
	num_var_syms_added}): Define new member functions.
	* include/abg-corpus.h (corpus::{get_sym_ids_of_fns_to_keep,
	get_sym_ids_of_vars_to_keep}): Declare new methods.
	* src/abg-corpus.cc (corpus::priv::{sym_id_fns_to_keep,
	sym_id_vars_to_keep}): Added data members.
	(symtab_build_visitor_type::{unrefed_fun_symbols,
	unrefed_var_symbols, sym_id_fns_to_keep, sym_id_vars_to_keep}):
	Added new data members.
	(symtab_build_visitor_type::symtab_build_visitor_type): Take two
	additional parameters for the function and variable symbol ids to
	keep.
	(symtab_build_visitor_type::add_fn_to_wip_fns): Take the function
	symbols to keep in account when building the exported symbol
	table.
	(symtab_build_visitor_type::add_var_to_wip_vars): Likewise, take
	the variable symbols to keep in account when building the exported
	symbol table.
	(corpus::priv::build_public_decl_table): Adjust the initialization
	of the visitor that walks the ABI artifacts to build the exported
	symbol table to know take a list of function/variable symbols to
	keep.
	(corpus::priv::build_unreferenced_symbols_tables): Ensure that the
	public table of functions/variables is built before doing the work
	of this function.  Also, if a list of variable/function symbols to
	keep is given, drop all symbols that are not in that list on the
	floor.
	(corpus::{get_sym_ids_of_fns_to_keep,
	get_sym_ids_of_vars_to_keep}): Define new accessors.
	* tools/abicompat.cc: New abicompat tool.
	* doc/manuals/abicompat.rst: New documentation source for
	abicompat.
	* doc/manuals/libabigail-tools.rst: Add an entry for the abicompat
	doc.
	* tests/test-abicompat.cc: New test harness for the 'abicompat'
	tool.
	* tests/Makefile.am: Build the runtestabicompat test harness and
	add it to the list of tests harnesses that are run by make check.
	* tests/data/test-abicompat/libtest0-fn-changed-libapp-v0.so: New
	test input.
	* tests/data/test-abicompat/libtest0-fn-changed-libapp-v1.so: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-app: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-0.suppr: Likewise
	* tests/data/test-abicompat/test0-fn-changed-report-0.txt: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-report-1.txt: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-app.cc: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-libapp.h: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-libapp-v0.cc: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-libapp-v1.cc: Likewise.
	* tests/data/test-abicompat/libtest1-fn-removed-v0.so: Likewise.
	* tests/data/test-abicompat/libtest1-fn-removed-v1.so: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-app: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-app.cc: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-report-0.txt: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-v0.cc: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-v1.cc: Likewise.
	* tests/data/test-abicompat/libtest2-var-removed-v0.so: Likewise.
	* tests/data/test-abicompat/libtest2-var-removed-v1.so: Likewise.
	* tests/data/test-abicompat/test2-var-removed-app: Likewise.
	* tests/data/test-abicompat/test2-var-removed-app.cc: Likewise.
	* tests/data/test-abicompat/test2-var-removed-report-0.txt: Likewise.
	* tests/data/test-abicompat/test2-var-removed-v0.cc: Likewise.
	* tests/data/test-abicompat/test2-var-removed-v1.cc: Likewise.
	* tests/data/test-abicompat/libtest3-fn-removed-v0.so: Likewise.
	* tests/data/test-abicompat/libtest3-fn-removed-v1.so: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-app: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-app.cc: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-report-0.txt: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-v0.cc: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-v1.cc: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-version-script-0 Likewise.:
	* tests/data/test-abicompat/test3-fn-removed-version-script-1: Likewise.
	* tests/data/Makefile.am: Add the new test inputs above to the
	source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-05 15:43:31 +01:00
Dodji Seketeli
f091ff1ac2 Fix status checking in abidw
Now that the status is a bit field, one needs to check the OK bit in
the status for successful operation state.  Oops.

	* tools/abidw.cc (main): Fix successful status checking.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-30 19:57:04 +01:00
Dodji Seketeli
f44110b326 Support comparing symbols not referenced by debug info
* doc/manuals/abidiff.rst: Adjust intro to mention that w/o debug
	info, abidiff now works but just report about added/removed
	symbols.  Add documentation about the new
	--no-unreferenced-symbols option.
	* include/abg-comparison.h (string_elf_symbol_map): New typedef.
	(diff_context::show_symbols_unreferenced_by_debug_info): Declare
	new accessors.
	* src/abg-comparison.cc
	(diff_context::priv::show_syms_unreferenced_by_di_): New data
	member.
	(diff_context::priv::priv): Adjust.
	(diff_context::show_symbols_unreferenced_by_debug_info): Implement
	these accessors.
	(corpus_diff::priv::{unrefed_fn_syms_edit_script_,
	unrefed_var_syms_edit_script_, added_unrefed_fn_syms_,
	deleted_unrefed_fn_syms_, added_unrefed_var_syms_,
	deleted_unrefed_var_syms_}): New data members.
	(corpus_diff::priv::diff_stats::{num_func_syms_removed,
	num_func_syms_added, num_var_syms_removed, num_var_syms_added}):
	New data members.
	(corpus_diff::priv::diff_stats::diff_stats): Adjust.
	(corpus_diff::ensure_lookup_tables_populated): Populate lookup
	tables for added/removed symbols that are not referenced by any
	debug info.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats): Compute
	stats for the added/removed symbols not referenced by any debug
	info.
	(corpus_diff::priv::emit_diff_stats): Emit stats about
	added/removed symbols that are not referenced by any debug info.
	(corpus_diff::length): Adjust to take in account added/removed
	symbols not referenced by any debug info.
	(show_linkage_name_and_aliases): New static function.
	(corpus_diff::report): When emitting a symbol name, emit its
	version too, and tell if it aliases other symbols.  Avoid emitted
	extra new lines.  Report added/removed symbols not referenced by
	any debug info.
	(compute_diff): In the overload for corpus_sptr, compute the diffs
	for symbols not referenced by debug info.
	* include/abg-corpus.h
	(corpus::get_unreferenced_{function,variable}_symbols): Declare
	new member functions.
	* src/abg-corpus.cc (corpus_priv::{unrefed_fun_symbols,
	unrefed_var_symbols}): New data members.
	(corpus_priv::build_unreferenced_symbols_tables): Define new
	member function.
	(struct comp_elf_symbols_functor): New functor.
	(corpus::is_empty): Adjust to take in account added/removed
	symbols not referenced by debug info.
	(corpus::{get_unreferenced_function_symbols,
	corpus::get_unreferenced_variable_symbols}): Define these
	accessors.
	* include/abg-dwarf-reader.h (enum status): Transform this into
	bitfields.  Add a STATUS_UNKNOWN value that has the value 0.
	(operator|(status, status), operator&(status, status))
	(operator|=(status&, status), operator&=(status, status)): New
	bit-wise operators to manipulate instances of the status bit-field.
	* src/abg-dwarf-reader.cc (get_version_for_symbol): Fix this to
	avoid returning garbage version sometimes.
	(read_debug_info_into_corpus): Fix this to return a non-null but
	empty corpus_sptr when there is no debug info available.
	(operator|(status, status), operator&(status, status))
	(operator|=(status&, status), operator&=(status, status)): Define
	these new bitwise operators to manipulate instances of the status
	bit-field.
	(read_corpus_from_elf): Now that the abigail::dwarf_reader::status
	is a bit-field, set it to reflect if debug info and/or symbol
	tables have been found.  Do not bail out if debug info hasn't been
	found.  Rather, keep going, and go look for symbols-only; this is
	a kind of operating in degraded mode.
	* include/abg-ir.h (elf_symbol::get_aliases_id_string): Add a flag
	that says if the current instance of elf_symbol should be included
	in the list of aliases or not.
	* src/abg-ir.cc (elf_symbol::get_aliases_id_string): Define it.
	* tests/data/test-diff-dwarf/test16-syms-only-v{0,1}.o: New test
	input.
	* tools/abidiff.cc
	(options::show_symbols_not_referenced_by_debug_info): New data
	member.
	(options:options): Adjust.
	(display_usage): Add an info string for the new
	--no-unreferenced-symbols command line option.
	(parse_command_line): Parse the new --no-unreferenced-symbols
	command line.
	(set_diff_context_from_opts): Set the diff_context according to
	the presence of --no-unreferenced-symbols.
	(main): Adjust for the fact that abigail::dwarf_reader::status is
	now a bit-field.
	* tools/abilint.cc (main): Adjust for the fact that
	abigail::dwarf_reader::status is now a bit-field..
	():
	* tests/data/test-diff-dwarf/test16-syms-only-report.txt: New test
	reference output.
	* tests/data/test-diff-dwarf/test16-syms-only-v{0,1}.cc: Source code
	for new test input.
	* tests/data/test-diff-dwarf/test17-non-refed-syms-v{0,1}.o: New
	test input.
	* tests/data/test-diff-dwarf/test17-non-refed-syms-v{0,1}.cc: New
	source code for test input.
	* tests/data/test-diff-dwarf/libtest18-alias-sym-v{0,1}.so: New
	test input.
	* tests/data/test-diff-dwarf/test18-alias-sym-report-0.txt:
	Reference output for new test input.
	* tests/data/test-diff-dwarf/test18-alias-sym-v{0,1}.cc: Source
	code for new test input.
	* tests/data/test-diff-dwarf/test18-alias-sym-version-script:
	Source code for new test input.
	* tests/Makefile.am: Add the new test materials to the source
	distribution.
	* tests/test-diff-dwarf.cc(in_out_specs): Add the new input tests
	above to the array of tests to run by this harness.
	(main): Emit empty reports for empty resulting diffs.
	* tests/data/test-diff-dwarf/test{0,8,9,12,14-inline-report,}-report.txt:
	Adjust.
	* tests/data/test-diff-filter/test{0,01,2,4,5,7,8,9,10,12,13,15-0,15-1}-report.txt:
	Likewise.
	* tests/data/test-diff-filter/test{19-enum,20-inline,}-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-report-{1,2}.txt:
	Likewise.
	* tests/data/test-diff-suppr/test{1,2}-typedef-suppr-report-1.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-22 23:04:40 +02:00
Dodji Seketeli
feea5df3fe Initial support for type suppressions
* include/abg-comparison.h (diff_category::SUPPRESSED_CATEGORY):
	New enumerator.
	(diff_category::{SIZE_OR_OFFSET_CHANGE_CATEGORY,
	VIRTUAL_MEMBER_CHANGE_CATEGORY): Update the enumerator values for
	these.
	(diff::EVERYTHING_CATEGORY): Adjust.
	(suppression_base, type_suppression): Declare new types.
	(suppression_ptr, suppressions_type, type_suppression_sptr)
	(type_suppressions_type): New typedefs.
	(read_type_suppressions, read_suppressions): Declare new
	functions.
	(diff_context::{suppressions, add_suppression, add_suppressions}):
	Declare new methods.
	(diff::is_suppressed): Declare new member function.
	(apply_suppressions): Declare new function & overloads.
	* src/abg-comparison.cc (is_type_diff): Define new static
	function.
	({suppression_base, type_suppression}::priv): Define new types.
	({suppression_base, type_suppression}::*): Define the methods of the new
	suppression_base, type_suppressions types.
	(read_type_suppression, read_type_suppressions, read_suppressions)
	(read_type_suppressions): Define new static functions.
	(diff_context::priv::supprssions_): New data member.
	(diff_context::{suppressions, add_suppression, add_suppressions}):
	New methods.
	(diff::is_filtered_out): Consider that a diff node that is in the
	SUPPRESSED_CATEGORY is filtered out.
	(diff::is_suppressed): Define new member function.
	(operator<<(ostream& o, diff_category c)): Support the
	SUPPRESSED_CATEGORY category.
	(corpus_diff::report): Apply suppressions before reporting
	anything.
	(category_propagation_visitor::visit_end): Do not propagate
	SUPPRESSED_CATEGORY.  This is just like what we do for
	REDUNDANT_CATEGORY.
	(struct suppression_categorization_visitor): New visitor.
	(apply_suppressions): Define function & overloads.
	* include/abg-ini.h (config::section::find_property): New method.
	(config::section): Fix end of class comment.
	* src/abg-ini.cc (config::section::find_property): Define new
	method.
	* tests/data/test-diff-suppr/test0-type-suppr-{0,1,2}.suppr: New
	test input files.
	* tests/data/test-diff-suppr/test0-type-suppr-report-{0,1,2,3}.txt:
	Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-v{0,1}.o: Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-v{0,1}.cc: Source code
	for new test input.
	* tests/data/test-diff-suppr/test1-typedef-suppr-v{0,1}.o: New test
	input files.
	* tests/data/test-diff-suppr/test1-typedef-suppr.h: Source code
	for new test input files.
	* tests/data/test-diff-suppr/test1-typedef-suppr-v{0,1}.c: Likewise
	* tests/data/test-diff-suppr/test1-typedef-suppr-{0,1}.suppr: New
	test input files.
	* tests/data/test-diff-suppr/test1-typedef-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test1-typedef-suppr-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test1-typedef-suppr-report-2.txt: Likewise.
	* tests/test-diff-suppr.cc: New test harness to run type suppression tests
	using the input files above.
	* tests/data/test-diff-suppr/test3-struct-suppr-0.suppr: New test input.
	* tests/data/test-diff-suppr/test3-struct-suppr-1.suppr: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-report-2.txt: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-v0.cc: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-v0.o: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-v1.cc: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-v1.o: Likewise.
	* tests/Makefile.am: Build the new runtestdiffsuppr test harness
	from the test-diff-filter.cc file.  Add the new test files to the
	build system and source distribution.
	* tools/bidiff.cc (options::suppressions): New data member.
	(display_usage): Add a help string for the new
	--suppressions command line switch.
	(parse_command_line): Parse the --suppressions command line
	switch.
	(set_diff_context_from_opts): Read the suppressions provided by
	the --suppression command line switch and stuff them into the diff
	context.
2014-10-13 17:44:44 +02:00
Dodji Seketeli
26869d665c Make all type diff types extend new type_diff_base type
* include/abg-comparison.h (type_diff_base, decl_diff_base): New
	types.
	(type_diff_base_sptr): New typedef.
	(pointer_diff, reference_diff, array_diff, qualified_type_diff)
	(enum_diff, class_diff, type_decl_diff, typedef_diff): Make this
	extend the new type_diff_base.
	* src/abg-comparison.cc (type_diff_base::priv, type_diff_base):
	Define these new types and their methods.
	(pointer_diff::pointer_diff, array_diff::array_diff)
	(reference_diff::reference_diff)
	(qualified_type_diff::qualified_type_diff, enum_diff::enum_diff)
	(class_diff::class_diff, type_decl_diff::type_decl_diff)
	(typedef_diff::typedef_diff): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-13 17:44:43 +02:00
Dodji Seketeli
74b9337efc Implement the abigail::ini::config abstraction
* include/abg-ini.h (config::config): Add an overload that take a
	path and sections.
	(config::{get,set}_sections): New accessors.
	(read_sections): Rename the previous read_config() functions into
	these.
	(read_config): Add these function declarations to really act on
	instances of abigail::ini::config.
	(write_section): Rename the previous write_config functions into
	these.
	(write_config): Add these function declarations to really act on
	instances of abigail::ini::config.
	* src/abg-ini.cc (class config::priv): Implement this.
	(config::{config, ~config, get_path, set_path, get_sections,
	set_sections}): Define these new methods.
	(read_sections): Rename the former read_config into this.
	(read_config): Add this function definitions to really act on
	instances of abigail::ini::config.
	(write_sections): Rename the former write_config into this.
	(write_config):: Add this function definitions to really act on
	instances of abigail::ini::config.
	* tools/binilint.cc (main): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-13 17:44:43 +02:00
Dodji Seketeli
284c9e488f Initial support of ini-style file parsing
* include/abg-ini.h: New file.
	* include/Makefile.am: Add include/abg-ini.h to the source
	distribution.
	* src/abg-ini.cc: New file.
	* src/Makefile.am: Add src/abg-ini.cc to the source distribution.
	* tools/binilint.cc: New testing tool.
	* tools/Makefile.am: Add tools/binilint.cc to the source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-13 17:44:43 +02:00
Dodji Seketeli
fccc516656 Put IR artifacts in the abigail::ir namespace
* include/abg-fwd.h: Wrap IR artifacts into abigail::ir namespace.
	Inject that new abigail::ir namespace into the abigail namespace.
	* include/abg-ir.h: Wrap IR artifacts into abigail::ir namespace.
	(function_decl::parameter::get_type_name): Adjust the call to
	abigail::get_type_name.  It's now a call to
	abigail::ir::get_type_name.
	* src/abg-ir.cc: Wrap IR artifacts into abigail::ir namespace.
	* include/abg-traverse.h: Wrap the ir traversing artifact into the
	abigail::ir namespace too.
	* src/abg-traverse.cc: Adjust.
	* include/abg-corpus.h: Wrap corpus type stuff into abigail::ir.
	* include/abg-dwarf-reader.h: Inject namespace abigail::ir stuff
	into the abigail::dwarf_reader namespace.
	* include/abg-reader.h: Inject namespace abigail::ir stuff into
	the abigail::xml_reader namespace.
	* src/abg-reader.cc: Adjust.
	* include/abg-writer.h: Inject namespace abigail::ir stuff into
	the abigail::xml_writer namespace.
	* src/abg-writer.cc: Inject namespace abigail::ir stuff into
	abigail namespace here too.
	* src/abg-hash.cc: Inject the abigail::ir namespace into the
	abigail namespace.
	* tools/abg-tools-utils.cc: Adjust for the injection of
	abigail::function_decl. It's now abigail::ir::function_decl.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-13 17:44:43 +02:00
Dodji Seketeli
2a77bead11 Implement generic diff tree walking and port categorization over it
* include/abg-comp-filter.h (apply_filter): Declare new overload
	that takes a corpus_diff_sptr ...
	* src/abg-comp-filter.cc (apply_filter): ... and define it.  On
	the existing overload for diff_sptr, make sure to traverse all
	diff nodes, even those that have already been traversed.
	* include/abg-comparison.h (enum diff_category): Remove
	NOT_REDUNDANT_CATEGORY, add REDUNDANT_CATEGORY.
	(operator&=, +operator<<): Declare new operators for enum diff_category.
	(diff_context::{forbid_traversing_a_node_twice,
	traversing_a_node_twice_is_forbidden):
	(diff_context::categorizing_redundancy): Remove this declaration.
	(diff_context::maybe_apply_filters): Declare a new overload that
	takes a corpus_diff_sptr.  And a take a new flag that says if it
	should visit all nodes including those that have already been
	visited.
	(diff::priv_): Make this data member protected.
	(diff::{begin_traversing, is_traversing, end_traversing,
	finish_diff_type, children_nodes, append_child_node,
	get_pretty_representation, chain_into_hierarchy, traverse}):
	Declare new member functions.
	(distinct_diff::{finish_diff_type, get_pretty_representation,
	chain_into_hierarchy}): Likewise.
	(distinct_diff::traverse): Remove.
	(pointer_diff::pointer_diff): Take the underlying type diff in
	parameter.
	(pointer_diff::{finish_diff_type, get_pretty_representation,
	chain_into_hierarchy}): Declare new member functions.
	(pointer_diff::traverse): Remove.
	(reference_type_def::reference_type_def): Take the underlying type
	diff in parameter.
	({array_type_def, reference_type_def}::{finish_diff_type,
	get_pretty_representation, chain_into_hierarchy}): Declare new
	member functions.
	({array_type_diff, reference_type_def}::traverse): Remove.
	(qualified_type_diff::qualified_type_diff): Take the underlying
	type diff in parameter.
	({enum_diff, qualified_type_diff, class_diff}::{finish_diff_type,
	get_pretty_representation, chain_into_hierarchy}): Declare new
	member functions.
	({enum_diff, qualified_type_diff, class_diff}::traverse): Remove.
	(is_class_diff): Declare new function.
	(base_diff::base_diff): Take the underlying type diff in
	parameter.
	({scope_diff, base_diff}::{finish_diff_type, get_pretty_representation,
	chain_into_hierarchy}): Declare new member functions.
	({scope_diff, base_diff}::traverse): Remove.
	(function_decl_diff::function_decl_diff): Take the return type
	diff as parameter.
	({function_decl_diff, type_decl_diff}::{finish_diff_type,
	get_pretty_representation, chain_into_hierarchy}): Declare new
	member functions.
	({function_decl_diff, type_decl_diff}::traverse): Remove.
	(typedef_diff::typedef_diff): Take the underlying type diff as
	parameter.
	(typedef::{finish_diff_type, get_pretty_representation,
	chain_into_hierarchy}): Declare new member functions.
	({typedef, translation_unit_diff}::traverse): Remove member
	function.
	(corpus_diff::{finish_diff_type, children_nodes,
	append_child_node, changed_variables, get_pretty_representation,
	chain_into_hierarchy}): Declare new member functions.
	(class diff_node_visitor::{visit_begin, visit_end}): Declare new
	member functions.
	(propagate_categories, print_diff_tree, categorizing_redundancy)
	(clear_redundancy_categorization, apply_filters): New functions
	and function overloads.
	* src/abg-comparison.cc (TRY_PRE_VISIT, TRY_PRE_VISIT_CLASS_DIFF)
	(TRY_POST_VISIT, TRY_POST_VISIT_CLASS_DIFF)
	(CATEGORIZE_REDUNDANCY_FROM_CHILD_NODE)
	(UPDATE_REDUNDANCY_CATEGORIZATION_FROM_NODE_SUBTREE)
	(TRAVERSE_DIFF_NODE_AND_PROPAGATE_CATEGORY)
	(TRAVERSE_MEM_DIFF_NODE_AND_PROPAGATE_CATEGORY)
	(TRAVERSE_MEM_FN_DIFF_NODE_AND_PROPAGATE_CATEGORY)
	(ENSURE_DIFF_NODE_TRAVERSED_ONCE)
	(ENSURE_MEM_DIFF_NODE_TRAVERSED_ONCE): Remove these macros.
	Hurrah.
	(diff_context::priv::categorizing_redundancy_): Remove.
	(diff_context::priv::forbid_traversing_a_node_twice_): Add new
	data member.
	(diff_context::priv::priv): Adjust.
	(diff_context::{forbid_traversing_a_node_twice,
	traversing_a_node_twice_is_forbidden}): Define new member
	functions.
	(diff_context::maybe_apply_filters): Once filters are applied (and
	categories are set to the relevant diff tree nodes, run a pass
	over the diff tree to propagate the categories to the relevant
	diff tree parent nodes.  Add an overload for corpus_diff_sptr.
	(diff_context::categorizing_redundancy): Remove member function.
	(diff_context::maybe_apply_filters): Define a new overload for
	corpus_diff_sptr
	(struct diff::priv::{finished_, traversing_, children_,
	pretty_representation_}):  New data members.
	(diff::priv::priv): Adjust.
	(diff::{begin_traversing, is_traversing, end_traversing,
	finish_diff_type, children_nodes, append_child_node, traverse,
	set_category, get_pretty_representation, chain_into_hierarchy}):
	Define new member functions.
	(diff::is_filtered_out): Do not refer to NOT_REDUNDANT_CATEGORY
	anymore.  Rather, use the new REDUNDANT_CATEGORY.
	({distinct_diff, var_diff, pointer_diff, array_diff,
	reference_diff, qualified_type_diff, enum_diff, class_diff,
	base_diff, scope_diff, function_decl_diff, type_decl_diff,
	typedef_diff}::{get_pretty_representation, chain_into_hierarchy,
	finish_diff_type}): Define new member functions.
	({distinct_diff, var_diff, pointer_diff, array_diff,
	reference_diff, qualified_type_diff, enum_diff, class_diff,
	base_diff, scope_diff, function_decl_diff, type_decl_diff,
	typedef_diff, translation_unit_diff}::traverse): Remove member
	functions.
	(operator&=, operator<<): Define new operators for diff_category.
	({function_decl_diff, typedef_diff}::priv::priv): Add a new
	constructor.
	(pointer_diff::{priv::priv, pointer_diff})
	(reference_diff::{priv::priv, reference_diff})
	(qualified_type_diff::{priv::priv, qualified_type_diff})
	(enum_diff::{priv::priv, enum_diff}, base_diff::{priv::priv,
	base_diff}, function_decl_diff::function_decl_diff): Take the
	underlying type diff in parameter.
	(compute_diff): Adjust the pointer_diff, reference_diff,
	qualified_type_diff, base_diff, function_decl_diff overloads.
	(class_diff::priv::{count_filtered_bases,
	count_filtered_subtype_changed_dm, count_filtered_changed_dm,
	count_filtered_changed_mem_fns, count_filtered_inserted_mem_fns,
	count_filtered_deleted_mem_fns}): Adjust for the call to
	diff_context::maybe_apply_filters.
	(corpus_diff::priv::{finished_, pretty_representation_}): New data
	member.
	(corpus_diff::priv::priv): New constructor.
	(corpus_diff::priv::clear_redundancy_categorization): Define new
	member function.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats):
	Adjust for call to diff_context::maybe_apply_filters.  Also, call
	clear_redundancy_categorization at the end.
	(corpus_diff::priv::categorize_redundant_changed_sub_nodes):
	Revisit logic.
	(corpus_diff::{chain_into_hierarchy, finish_diff_type,
	children_nodes, append_child_node, changed_variables,
	get_pretty_representation}): Define new member functions.
	(corpus_diff::report): Categorize redundancy for every top level
	function/variable diff.
	(corpus_diff::traverse): Adjust to the new traversing interface.
	(diff_node_visitor::{visit_begin, visit_end}): Define new member
	functions.
	(struct category_propagation_visitor, struct diff_node_printer)
	(struct redundancy_marking_visitor, struct
	redundancy_clearing_visitor): New diff tree node visitors.
	(propagate_categories, print_diff_tree, categorize_redundancy)
	(clear_redundancy_categorization, apply_filters): Define new
	functions.
	* tests/Makefile.am: Add the new tests/print-diff-tree.cc to the
	source distribution.  Build it into a tests/printdifftree binary.
	* tools/abidiff.cc (print_diff_tree): Add debugging functions to
	call from within the debugger.  By default, this function and its
	overloads are not compiled.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-10 13:18:04 +02:00
Dodji Seketeli
e807eb86e6 Do not install the abisym program
* tools/Makefile.am: Do not install abisym.  It's really there
	just for testing purposes and is of almost no use for generic
	users.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-26 16:14:18 +02:00
Dodji Seketeli
d041c1f5dd Rename bi* tools to abi* tools
* tests/data/test-bidiff: Rename this directory to
	tests/data/test-abidiff.
	* tests/test-bidiff.cc: Renamed this to tests/test-abidiff.cc.
	* tools/biar.cc: Renamed to tools/abiar.cc
	* tools/bidiff.cc: Renamed to tools/abidiff.cc
	* tools/bidw.cc: Renamed to tools/abidw.cc
	* tools/bilint.cc: Renamed to tools/abilint.cc
	* tools/bisym.cc: Renamed to tools/abisym.cc
	* tests/test-alt-dwarf-file.cc: Renamed references to bidw* to abidw*.
	* tests/test-diff-filter.cc: Renamed references to bidiff to abidiff.
	* tests/test-lookup-syms.cc: Renamed references to bisym to abisym.
	* tools/Makefile.am: Adjust.
	* tests/Makefile.am: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-26 10:58:16 +02:00
Dodji Seketeli
edd8a04291 Light style cleanup in tools/bidiff.cc
* tools/bidiff.cc (display_usage): Remove useless space before '&'.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-19 12:25:44 +02:00
Dodji Seketeli
fde3436568 Better support for inline related diffs
* include/abg-comparison.h
	(diff_category::HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY): New
	enumerator.
	(diff_category::EVERYTHING_CATEGORY): Adjust.
	* include/abg-ir.h (elf_symbol::get_aliases_id_string)
	(elf_symbol::does_alias, elf_symbols_alias)
	(compute_aliases_for_elf_symbol): Declare new functions ...
	* src/abg-ir.cc (elf_symbol::get_aliases_id_string)
	(elf_symbol::does_alias, elf_symbols_alias)
	(compute_aliases_for_elf_symbol): ... and define them.
	(function_decl::operator==): Take in account elf symbol aliases.
	* src/abg-comp-filter.cc (function_name_changed_but_not_symbol):
	Define new static functions.
	(harmless_filter::visit): Categorize function name changes that
n	doesn't impact underlying elf symbols (or the fact that two
	symbols were aliases and are not anymore) as harmless.
	* src/abg-comparison.cc (function_decl_diff::report): Properly
	report function name changes, or symbol aliases changes for that
	matter.  Also report inline-ness declaration changes.
	* src/abg-dwarf-reader.cc (die_is_declared_inline): New static
	function.
	(build_function_decl): Use the above.
	* tools/bidiff.cc (set_diff_context_from_opts): Add
	abigail::comparison::HARMLESS_SYMBOL_ALIAS_CHANGE_CATEORY into the
	harmless change camp.
	* tests/data/test-diff-dwarf/test14-inline-report.txt: New test
	input.
	* tests/data/test-diff-dwarf/test14-inline-v0.o: Likewise.
	* tests/data/test-diff-dwarf/test14-inline-v1.o: Likewise.
	* tests/data/test-diff-dwarf/test14-inline-v0.cc: Source code for
	test input.
	* tests/data/test-diff-dwarf/test14-inline-v1.cc: Source code for
	test input.
	* tests/test-diff-dwarf.cc: Run this test harness over the new
	input above.
	* 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/test20-inline-v0.o: New test input.
	* tests/data/test-diff-filter/test20-inline-v1.o: New test input.
	* tests/data/test-diff-filter/test20-inline-v0.cc: Source code for
	test input.
	* tests/data/test-diff-filter/test20-inline-v1.cc: Likewise.
	* tests/test-diff-filter.cc: Run this test harness over the new
	input above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-09-16 15:10:41 +02:00