Hello, The symptom of the issue at hand is that sometimes there can be types missing from the abixml output. This happens when analysing some C++ code bases. The core of the issue is the following. Support we have a type "struct S" defined somewhere as: struct S // #0 { int dm1; char dm2; }; S s; Suppose that in another translation unit, we have the class 'S' being extended to add a member type to it: struct S // #1 { typedef int dm1_type; }; typedef S::dm1_type Integer; Integer something; When emitting the abixml for the codebase, the definition of the typedef S::dm1_type can be missing. Note that in location #1, struct S is considered declaration-only. It's definition is in another translation unit, in location #0. So the abixml writer emits the 'struct S' defined in location #0, but forgets to emit the 'struct S' in #1, which is indirectly used for the sole purpose of using its member type S::dm1_type. This patch emits the S::dm1_type type that is mistakenly forgotten today. Now that the "struct S" of #1 is also emitted, a tangent problem is uncovered: S in #0 can be wrongly thought to be equivalent to S in #1, for ABI purposes This is because of an ODR-based optimization that is used for C++. That is, the two struct S can be wrongly considered equivalent just because they have the same name. Note that ODR means "One Definition Rule[1]" This patch removes the ODR-based optimization and thus fixes many of the issues uncovered by the previous changes. The patch also uncovered that some non-static variables were sometimes wrongly being added to the set of exported variables, while libabigail reads corpora from abixml. The patch fixes this as well. [1]: One Definition Rule: https://en.wikipedia.org/wiki/One_Definition_Rule * include/abg-corpus.h (corpus::{record_canonical_type, lookup_canonical_type}): Remove function declarations. * src/abg-corpus-priv.h (corpus::priv::canonical_types_): Remove data member. * src/abg-corpus.cc (corpus::{record_canonical_type, lookup_canonical_type}): Remove functions. * src/abg-ir.cc (type_eligible_for_odr_based_comparison): Remove static function. (type_base::get_canonical_type_for): Don't perform the ODR-based optimization for C++ anymore. * src/abg-reader.cc (read_context&::maybe_add_var_to_exported_decls): Don't add a variable that hasn't been added to its scope. Otherwise, it means we added a variable that wasn't yet properly constructed. Also add a new overload for var_decl_sptr&. (build_var_decl): Do not add the var to its the set of exported declaration before we are sure it has been fully constructed and added to the scope it belongs. (build_class_decl): Only add *static* data members to the list of exported declarations. (handle_var_decl): A var decl seen here is a global variable declaration. Add it to the list of exported declarations. * src/abg-writer.cc (write_context::decl_only_type_is_emitted): Constify parameter. (write_translation_unit): Do not forget to emit referenced types that were maybe not canonicalized. Also, avoid using noop_deleter when it's not necessary. (write_namespace_decl): Do not forget to emit canonicalized types that are present in namespaces other than the global namespace. * tests/runtestslowselfcompare.sh.in: New test that compares libabigail.so against its own ABIXML representation. * tests/Makefile.am: Add the new test runtestslowselfcompare.sh to source distribution. This test is too slow to be run during the course of 'make check'. It takes more than 5 minutes on my slow box here. Rather, it can be run using 'make check-self-compare'. I plan to run this before releases now. * tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Adjust. * tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise. * tests/data/test-annotate/test0.abi: Likewise. * tests/data/test-annotate/test13-pr18894.so.abi: Likewise. * tests/data/test-annotate/test14-pr18893.so.abi: Likewise. * tests/data/test-annotate/test15-pr18892.so.abi: Likewise. * tests/data/test-annotate/test17-pr19027.so.abi: Likewise. * tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise. * tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise. * tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise. * tests/data/test-annotate/test21-pr19092.so.abi: Likewise. * tests/data/test-read-dwarf/PR22015-libboost_iostreams.so.abi: Likewise. * tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise. * tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi: Likewise. * tests/data/test-read-dwarf/PR26261/PR26261-exe.abi: Likewise. * tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi: Likewise. * tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise. * tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise. * tests/data/test-read-dwarf/test0.abi: Likewise. * tests/data/test-read-dwarf/test0.hash.abi: Likewise. * tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise. * tests/data/test-read-dwarf/test11-pr18828.so.abi: Likewise. * tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise. * tests/data/test-read-dwarf/test14-pr18893.so.abi: Likewise. * tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise. * tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise. * tests/data/test-read-dwarf/test17-pr19027.so.abi: Likewise. * tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise. * tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise. * tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise. * tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise. * tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise. * tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise. * tests/data/test-read-write/test28-without-std-fns-ref.xml: Likewise. * tests/data/test-read-write/test28-without-std-vars-ref.xml: Likewise. * tests/data/test-read-write/test6.xml: Likewise. Signed-off-by: Dodji Seketeli --- Makefile.am | 6 + configure.ac | 2 + include/abg-corpus.h | 2 - src/abg-corpus-priv.h | 1 - src/abg-corpus.cc | 40 - src/abg-ir.cc | 113 +- src/abg-reader.cc | 30 +- src/abg-writer.cc | 72 +- tests/Makefile.am | 15 +- .../data/test-annotate/libtest24-drop-fns-2.so.abi | 38 +- tests/data/test-annotate/libtest24-drop-fns.so.abi | 38 +- tests/data/test-annotate/test0.abi | 16 +- tests/data/test-annotate/test14-pr18893.so.abi | 14712 ++- tests/data/test-annotate/test15-pr18892.so.abi | 43434 ++++--- tests/data/test-annotate/test17-pr19027.so.abi | 69043 +++++++---- .../test18-pr19037-libvtkRenderingLIC-6.1.so.abi | 13622 ++- .../test19-pr19023-libtcmalloc_and_profiler.so.abi | 36146 +++--- .../test20-pr19025-libvtkParallelCore-6.1.so.abi | 37504 +++--- tests/data/test-annotate/test21-pr19092.so.abi | 6712 +- .../PR22015-libboost_iostreams.so.abi | 2273 +- tests/data/test-read-dwarf/PR22122-libftdc.so.abi | 1025 +- .../PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi | 811 +- tests/data/test-read-dwarf/PR26261/PR26261-exe.abi | 30 +- .../test-read-dwarf/libtest24-drop-fns-2.so.abi | 20 +- .../data/test-read-dwarf/libtest24-drop-fns.so.abi | 8 +- tests/data/test-read-dwarf/test-libandroid.so.abi | 110042 ++++++++++-------- tests/data/test-read-dwarf/test0.abi | 12 +- tests/data/test-read-dwarf/test0.hash.abi | 12 +- .../data/test-read-dwarf/test10-pr18818-gcc.so.abi | 6983 +- tests/data/test-read-dwarf/test11-pr18828.so.abi | 53964 ++++----- tests/data/test-read-dwarf/test12-pr18844.so.abi | 61126 +++++----- tests/data/test-read-dwarf/test14-pr18893.so.abi | 11252 +- tests/data/test-read-dwarf/test15-pr18892.so.abi | 34025 +++--- tests/data/test-read-dwarf/test16-pr18904.so.abi | 59148 +++++----- tests/data/test-read-dwarf/test17-pr19027.so.abi | 38119 ++++-- .../test18-pr19037-libvtkRenderingLIC-6.1.so.abi | 9447 +- .../test19-pr19023-libtcmalloc_and_profiler.so.abi | 28340 +++-- .../test20-pr19025-libvtkParallelCore-6.1.so.abi | 26872 +++-- tests/data/test-read-dwarf/test21-pr19092.so.abi | 5950 +- .../test22-pr19097-libstdc++.so.6.0.17.so.abi | 68467 +++++++---- .../test-read-dwarf/test9-pr18818-clang.so.abi | 4830 +- .../test-read-write/test28-without-std-fns-ref.xml | 26 +- .../test28-without-std-vars-ref.xml | 42 +- tests/data/test-read-write/test6.xml | 6 +- tests/runtestslowselfcompare.sh.in | 13 + 45 files changed, 444887 insertions(+), 299502 deletions(-) create mode 100644 tests/runtestslowselfcompare.sh.in I am attaching the gzipped form of this patch as it's too big otherwise.