libabigail/tests/data/test-annotate/test0.abi
Dodji Seketeli cac59a176a Bug 26769 - Fix missing types in abixml output
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 <dodji@redhat.com>
2020-11-23 13:02:34 +01:00

117 lines
7.1 KiB
Plaintext

<abi-corpus architecture='elf-amd-x86_64'>
<elf-needed>
<dependency name='libstdc++.so.6'/>
<dependency name='libm.so.6'/>
<dependency name='libgcc_s.so.1'/>
<dependency name='libc.so.6'/>
</elf-needed>
<elf-function-symbols>
<!-- ns0::bar(int, ...) -->
<elf-symbol name='_ZN3ns03barEiz' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- ns0::baz(int&) -->
<elf-symbol name='_ZN3ns03bazERi' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- ns0::foo(char*, long) -->
<elf-symbol name='_ZN3ns03fooEPcl' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- ns0::bar2(ns0::E&) -->
<elf-symbol name='_ZN3ns04bar2ERNS_1EE' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- ns0::baz2(int&) -->
<elf-symbol name='_ZN3ns04baz2ERi' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- __libc_csu_fini -->
<elf-symbol name='__libc_csu_fini' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- __libc_csu_init -->
<elf-symbol name='__libc_csu_init' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- _fini -->
<elf-symbol name='_fini' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- _init -->
<elf-symbol name='_init' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- _start -->
<elf-symbol name='_start' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- main -->
<elf-symbol name='main' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
</elf-function-symbols>
<elf-variable-symbols>
<!-- _IO_stdin_used -->
<elf-symbol name='_IO_stdin_used' size='4' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<!-- global -->
<elf-symbol name='global' size='4' type='object-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
</elf-variable-symbols>
<abi-instr version='1.0' address-size='64' path='test0.cc' comp-dir-path='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf' language='LANG_C_plus_plus'>
<!-- char -->
<type-decl name='char' size-in-bits='8' id='type-id-1'/>
<!-- int -->
<type-decl name='int' size-in-bits='32' id='type-id-2'/>
<!-- long int -->
<type-decl name='long int' size-in-bits='64' id='type-id-3'/>
<!-- long long int -->
<type-decl name='long long int' size-in-bits='64' id='type-id-4'/>
<!-- unnamed&#45;enum&#45;underlying&#45;type&#45;32 -->
<type-decl name='unnamed-enum-underlying-type-32' is-anonymous='yes' size-in-bits='32' alignment-in-bits='32' id='type-id-5'/>
<!-- variadic parameter type -->
<type-decl name='variadic parameter type' id='type-id-6'/>
<!-- void -->
<type-decl name='void' id='type-id-7'/>
<!-- char* -->
<pointer-type-def type-id='type-id-1' size-in-bits='64' id='type-id-8'/>
<!-- int& -->
<reference-type-def kind='lvalue' type-id='type-id-2' size-in-bits='64' id='type-id-9'/>
<!-- ns0::E& -->
<reference-type-def kind='lvalue' type-id='type-id-10' size-in-bits='64' id='type-id-11'/>
<!-- namespace ns0 -->
<namespace-decl name='ns0'>
<!-- enum ns0::E -->
<enum-decl name='E' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='19' column='1' id='type-id-10'>
<underlying-type type-id='type-id-5'/>
<enumerator name='e0' value='0'/>
<enumerator name='e1' value='1'/>
</enum-decl>
<!-- typedef long long int ns0::long_long -->
<typedef-decl name='long_long' type-id='type-id-4' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='25' column='1' id='type-id-12'/>
<!-- void ns0::bar(int, ...) -->
<function-decl name='bar' mangled-name='_ZN3ns03barEiz' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='12' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='_ZN3ns03barEiz'>
<!-- parameter of type 'int' -->
<parameter type-id='type-id-2'/>
<parameter is-variadic='yes'/>
<!-- void -->
<return type-id='type-id-7'/>
</function-decl>
<!-- void ns0::baz(int&) -->
<function-decl name='baz' mangled-name='_ZN3ns03bazERi' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='16' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='_ZN3ns03bazERi'>
<!-- parameter of type 'int&' -->
<parameter type-id='type-id-9'/>
<!-- void -->
<return type-id='type-id-7'/>
</function-decl>
<!-- void ns0::bar2(ns0::E&) -->
<function-decl name='bar2' mangled-name='_ZN3ns04bar2ERNS_1EE' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='22' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='_ZN3ns04bar2ERNS_1EE'>
<!-- parameter of type 'ns0::E&' -->
<parameter type-id='type-id-11'/>
<!-- void -->
<return type-id='type-id-7'/>
</function-decl>
<!-- ns0::long_long ns0::baz2(int&) -->
<function-decl name='baz2' mangled-name='_ZN3ns04baz2ERi' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='28' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='_ZN3ns04baz2ERi'>
<!-- parameter of type 'int&' -->
<parameter type-id='type-id-9'/>
<!-- typedef ns0::long_long -->
<return type-id='type-id-12'/>
</function-decl>
<!-- long int ns0::foo(char*, long int) -->
<function-decl name='foo' mangled-name='_ZN3ns03fooEPcl' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='45' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='_ZN3ns03fooEPcl'>
<!-- parameter of type 'char*' -->
<parameter type-id='type-id-8'/>
<!-- parameter of type 'long int' -->
<parameter type-id='type-id-3'/>
<!-- long int -->
<return type-id='type-id-3'/>
</function-decl>
</namespace-decl>
<!-- int main() -->
<function-decl name='main' mangled-name='main' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='49' column='1' visibility='default' binding='global' size-in-bits='64' elf-symbol-id='main'>
<!-- int -->
<return type-id='type-id-2'/>
</function-decl>
<!-- int global -->
<var-decl name='global' type-id='type-id-2' mangled-name='global' visibility='default' filepath='/home/dodji/git/libabigail/dwarf/tests/data/test-read-dwarf/test0.cc' line='3' column='1' elf-symbol-id='global'/>
</abi-instr>
</abi-corpus>