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>
* 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>
* include/abg-corpus.h (corpus::{g,s}et_{fun,var}_symbol_map{_sptr}):
Declare new accessors.
(corpus::lookup_{variable,function}_symbol): Declare new member
functions.
* src/abg-corpus.cc (corpus::{g,s}et_{fun,var}_symbol_map{_sptr}):
Define new accessors.
(corpus::lookup_{variable,function}_symbol): Define new member
functions.
* include/abg-ir.h (string_elf_symbol_sptr_map_type)
(string_elf_symbol_sptr_map_sptr, elf_symbols)
(string_elf_symbols_map_type, string_elf_symbols_map_sptr): New
convenience typedefs.
(elf_symbol::{get_main_symbol, is_main_symbol, get_next_alias,
has_aliases, add_alias, get_id_string,
get_name_and_version_from_id, operator=}): Declare new member
functions.
* src/abg-ir.cc (elf_symbol::{get_main_symbol, is_main_symbol,
get_next_alias, has_aliases, add_alias, get_id_string,
get_name_and_version_from_id, operator=}): Define new member
functions.
* include/abg-reader.h (read_corpus_from_file): Take a shared
pointer to corpus.
* src/abg-reader.cc (read_context::{g,s}et_corpus): Define these.
(build_elf_symbol_db, build_elf_symbol_from_reference)
(read_symbol_db_from_input): Define new functions.
(read_corpus_from_input): Adjust. Make it read symbol databases.
(build_elf_symbol): Harden this.
(build_{var,function}_decl): Read the symbol reference. Do not
read the local symbol serialization anymore.
(read_corpus_from_archive): Adjust.
(read_corpus_from_file): Take a reference to a shared pointer to
corpus, rather than a reference to the corpus.
(read_corpus_from_native_xml): Only keep the overload that returns
a corpus. Set the current context with the corpus.
* src/abg-dwarf-reader.cc (addr_elf_symbol_sptr_map_type)
(addr_elf_symbol_sptr_map_sptr): New convenience typedefs.
(read_context::{fun_sym_addr_sym_index_map_,
var_sym_addr_sym_index_map_): Remove.
(read_context::{fun,var}_addr_sym_map_): New. Replace the above
that got removed.
(read_context::{var,fun}_syms_): New.
(read_context::lookup_elf_{fn,var}_symbol_from_address): Adjust.
(read_context::{fun,var}_addr_sym_map{_sptr}): New.
(read_context::{fun,var}_syms{_sptr}): New.
(read_context::load_symbol_maps): Replace
read_context::load_symbol_addr_to_index_maps. Adjust to load all
the new maps.
(read_context::maybe_load_symbol_maps): New.
(read_debug_info_into_corpus): Renamed build_corpus into this.
Update to load symbol maps and set it to the corpus.
* src/abg-writer.cc (write_context::get_fun_symbol_map): New
accessor.
(write_elf_symbol_aliases, write_elf_symbol_reference)
(write_elf_symbols_table): Define new static functions.
(write_var_decl): Write the reference to the underlying symbol of
the variable. Do not write the full symbol here anymore.
(write_function_decl): Likewise, write the reference to the
underlying symbol of the function. Do not write the full symbol
here anymore.
(write_corpus_to_native_xml): Write the symbol databases at the
beginning of the corpus document.
* src/abg-comparison.cc
(corpus_diff::priv::ensure_lookup_tables_populated): Now that the
corpus has symbols, check if a the symbol of an allegedly deleted
function (resp. variable) is deleted; if not, then do not report
the function (resp. variable) as deleted. Similarly, check if the
symbol of an allegedly added function (resp. variable) is added.
if not, the do not report the function (resp. variable) as added.
* tests/test-write-read-archive.cc (main): Adjust.
* tools/biar.cc (extract_tus_from_archive): Likewise.
* tests/data/test-diff-filter/test9-report.txt: Adjust.
* tests/data/test-read-dwarf/test0.abi: Likewise.
* tests/data/test-read-dwarf/test1.abi: Likewise.
* tests/data/test-read-dwarf/test2.so.abi: Likewise.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
* include/abg-reader.h (read_corpus_from_native_xml)
(read_corpus_from_native_xml_file): Declare new entry points.
* include/abg-writer.h (write_corpus_to_native_xml)
(write_corpus_to_native_xml_file): Likewise.
* src/abg-reader.cc (read_translation_unit_from_input): Renamed
read_input into this. Support new 'path' attribute for
'abi-instr' XML element.
(read_corpus_from_input): New static function.
(read_translation_unit_from_file)
(read_translation_unit_from_buffer)
(read_translation_unit_from_istream): Update wrt read_input ->
read_translation_unit_from_input.
(read_corpus_from_native_xml, read_corpus_from_native_xml)
(read_corpus_from_native_xml_file): Define new entry points.
* src/abg-writer.cc (write_translation_unit): Write 'path'
attribute into the 'abi-instr' xml element.
(write_corpus_to_native_xml, write_corpus_to_native_xml_file):
Define new entry points.
* tools/abg-tools-utils.h (file_type::{FILE_TYPE_XML_CORPUS,
FILE_TYPE_ZIP_CORPUS}): New enumerators.
* tools/abg-tools-utils.cc (guess_file_type): Support detection of
the new xml file format containing a document root 'abi-corpus'
root element.
* tools/bidiff.cc (main): Support diffing xml corpus-es and zip
corpus-es.
* tools/bidw.cc (main): Recognize elf files before reading them.
* tools/bilint.cc (main): Support reading xml/zip corpus-es too.
* tests/data/test-read-write/test[0-23].xml: Update 'path'
attribute.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
* include/abg-libxml-utils.h (new_reader_from_istream): Declare
new public entry point.
* src/abg-libxml-utils.cc (xml_istream_input_read)
(xml_istream_input_close): New static functions.
(new_reader_from_istream): Define new public input function.
* include/abg-reader.h (read_translation_unit_from_istream):
Declare new entry points.
* src/abg-reader.cc (read_translation_unit_from_istream): Define
new entry points.
* tools/bilint.cc (options::{read_from_stdin, noout}): New
members.
(display_usage): Document --stdin and --noout.
(parse_command_line): Adjust to consider that no option on the
command line means reading from stdin, just like --stdin. Support
the --noout option as well.
(main): Support Read the abi instr from stdin; in that case, what
was read is just serialized back to stdout, unless --noout was
supplied.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
* include/abg-reader.h: New file with abigail::xml_reader APIs.
* include/abg-writer.h: New file with abigail::xml_writer APIs.
* include/Makefile.am: Add the new files above to the source
distribution.
* src/abg-reader.cc: Update top-file comments.
(namespace xml_reader): Rename namespace
reader into this.
(read_to_translation_unit, read_corpus_from_archive): New static
functions.
(read_translation_unit_from_file)
(read_translation_unit_from_file, read_corpus_from_file): New
entry points.
(struct array_deleter): New functor.
(translation_unit::read): Remove this.
* src/abg-writer.cc: Update top file comments.
(namespace xml_writer): Rename namespace
writer into this.
(struct archive_write_ctxt): New internal type.
(create_archive_write_context, write_translation_unit_to_archive)
(write_translation_unit, write_corpus_to_archive): New low level
static functions overloads.
(write_corpus_to_archive, write_translation_unit): Public higher
level overloads.
(translation_unit::write): Remove.
(dump): Update for new xml_writer namespace.
* include/abg-ir.h (translation_unit::{read, write}): Remove these
serialization methods.
* include/abg-corpus.h (corpus_sptr): New convenience typedef.
(corpus::{read, write}): Remove these methods.
* src/abg-corpus.cc (corpus::{read, write})
(corpus::impl::{serialized_tus, archive}): Remove these members.
(corpus::impl::{get_archive, close_archive, write_tu_to_archive,
read_to_translation_unit}): Remove these methods.
* tests/test-bidiff.cc (main): Update for usage of the new
xml_reader API.
* tests/test-read-write.cc (main): Likewise. Update for the usage
of the new xml_writer API, too.
* tests/test-walker.cc (main): Update for the usage of the new
xml_reader API.
* tests/test-write-read-archive.cc (main): Likewise. And for the
xml_writer API, too.
* tools/biar.cc (add_tus_to_archive, extract_tus_from_archive): Likewise.
* tools/bidiff.cc (main): Likewise, for xml_reader APIs.
* tools/bilint.cc (main): Likewise, for xml_writer APIs, too.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>