libabigail/tests/data/test-read-common/test-PR26568-1.c

19 lines
275 B
C
Raw Permalink Normal View History

Add regression tests for ctf reading This patch implements some regression tests for ctf reading. Since the code shares a lot of functionalities already used in the readi-dwarf test, a library was built and test common harness were moved to a common location. So input files for test-read-{dwarf,ctf}.cc now are located in: tests/data/test-read-common directory, ABIs description are stored in the same location but in a separate file, one for each binary debugging information: (e.g, test4-ctf.so.abi and test4-dwarf.so.abi) * tests/test-read-ctf.cc: New ctf reading regression test. * tests/test-read-common.cc: New library to be used with test-read-{ctf,dwarf}.cc. * tests/test-read-common.h: Likewise. * tests/test-annotate.cc (in_out_specs): Adjust path for input files. * tests/Makefile.am: Build new tests/test-read-ctf.cc file. * tests/data/Makefile.am: Add test inputs and expected files. Add libtestreadcommon.a test library and use it for test-read-{ctf,dwarf}. * tests/test-read-dwarf.cc: Adapt test to use libtestreadcommon.a in test-read-common.{cc,h}. * tests/data/test-annotate/test3.so.abi: Adjust ELF input path file location to ./tests/data/test-read-common. * tests/data/test-annotate/test4.so.abi: Likewise. * tests/data/test-read-common/PR26261: Move test harness to test-read-common directory. * tests/data/test-read-common/PR27700: Likewise. * tests/data/test-read-common/test-PR26568-*: Likewise. * tests/data/test-read-common/test3.{c,so}: Likewise. * tests/data/test-read-common/test4.{c,so}: Likewise. * tests/data/test-read-common/crti*: Helper object to export _init and _fini sysmbols. * tests/data/test-read-ctf/test-ambiguous-struct-A.c: New testcase. * tests/data/test-read-ctf/test-ambiguous-struct-B.c: Likewise. * tests/data/test-read-ctf/test-conflicting-type-syms-a.c: Likewise. * tests/data/test-read-ctf/test-conflicting-type-syms-b.c: Likewise. * tests/data/test-read-ctf/test-enum.c: Likewise. * tests/data/test-read-ctf/test-enum-many.c: Likewise. * tests/data/test-read-ctf/test-enum-symbol.c: Likewise. * tests/data/test-read-ctf/test-struct-iteration.c: Likewise. * tests/data/test-read-ctf/test-dynamic-array.c: Likewise. * tests/data/test-read-ctf/test0.c: Likewise. * tests/data/test-read-ctf/test1.c: Likewise. * tests/data/test-read-ctf/test2.c: Likewise. * tests/data/test-read-ctf/test5.c: Likewise. * tests/data/test-read-ctf/test7.{c,h}: Likewise. * tests/data/test-read-ctf/test8.c: Likewise. * tests/data/test-read-ctf/test9.c: Likewise. * tests/data/test-read-ctf/test-ambiguous-struct-A.o.hash.abi: Testcase expected result. * tests/data/test-read-ctf/PR26261/PR26261-exe.abi: Likewise. * tests/data/test-read-ctf/PR27700/test-PR27700.abi: Likewise. * tests/data/test-read-ctf/test-ambiguous-struct-A.o.hash.abi: Likewise. * tests/data/test-read-ctf/test-ambiguous-struct-B.o.hash.abi: Likewise. * tests/data/test-read-ctf/test-conflicting-type-syms-a.o.hash.abi: Likewise. * tests/data/test-read-ctf/test-conflicting-type-syms-b.o.hash.abi: Likewise. * tests/data/test-read-ctf/test-enum.o.abi: Likewise. * tests/data/test-read-ctf/test-enum-many.o.hash.abi: Likewise. * tests/data/test-read-ctf/test-enum-symbol.o.hash.abi: Likewise. * tests/data/test-read-ctf/test-struct-iteration.o.abi: Likewise. * tests/data/test-read-ctf/test-dynamic-array.o.abi: Likewise. * tests/data/test-read-ctf/test0: Likewise. * tests/data/test-read-ctf/test0*.abi: Likewise. * tests/data/test-read-ctf/test1.so: Likewise. * tests/data/test-read-ctf/test1*.abi: Likewise. * tests/data/test-read-ctf/test2.so: Likewise. * tests/data/test-read-ctf/test2*.abi: Likewise. * tests/data/test-read-ctf/test3.so.abi: Likewise. * tests/data/test-read-ctf/test4*.abi: Likewise. * tests/data/test-read-ctf/test5.o.abi: Likewise. * tests/data/test-read-ctf/test7.o.abi: Likewise. * tests/data/test-read-ctf/test8.o.abi: Likewise. * tests/data/test-read-ctf/test9.o.abi: Likewise. * tests/data/test-read-dwarf/PR26261/PR26261-exe.abi: Update expected abixml file. * tests/data/test-read-dwarf/PR27700/test-PR27700.abi: Likewise. * tests/data/test-read-dwarf/test-PR26568-1.*.abi: Likewise. * tests/data/test-read-dwarf/test3*.abi: Likewise. * tests/data/test-read-dwarf/test4*.abi: Likewise. * doc/api/libabigail.doxy: Add tests/test-read-common.{cc,h} to doxygen. Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-12-14 06:25:15 +00:00
/* gcc -std=c89 -gctf -g -mtune=generic -march=x86-64 -c \
* -o test-PR26568-1.o test-PR26568-1.c */
Bug 26568 - Union should support more than one anonymous member When building a union type we try to ensure that each member is present only once. This is because the code to build the union is also used to actually update a partially constructed union. To do so, before adding a member to the union, the member is looked up (among the current members) by name to see if it's already present or not. But then for anonymous members, the name of the member is empty. After the first anonymous member is added to the union, subsequent look-ups with an empty name all succeed. So no more than one anonymous member is added to the union. Oops. A way to fix this is to perform the lookup by taking into account the type of the anonymous data member, not its (empty) name. We already do this for anonymous data members of classes/structs. This patch thus uses that type-based anonymous data member lookup for unions. But then now that unions can have several anonymous members, another issue was uncovered. Array types whose elements are of anonymous type can be wrongly considered different because of canonicalization issues. Let's suppose we have these two arrays whose internal pretty representation are: "__anonymous_struct_1__ foo[5]" and "__anonymous_struct_2__ foo[5]" These are arrays of 5 elements of type anonymous struct. Suppose the anonymous structs "__anonymous_struct_1__" and "__anonymous_struct_2__" are structurally equivalent. Because the internal names of these array element types are different, the internal pretty representations of the arrays are different. And thus the canonical types of the two arrays are different. And that's wrong. In this particular case, they should have the same canonical type and thus be considered equivalent. This patch thus teaches 'get_type_name' to make the internal type name of anonymous types of a given kind be the same. Thus, making all arrays of 5 anonymous struct have the same pretty representation: "__anonymous_struct__ foo[5]" This gives the type canonicalizer a chance to detect that those arrays having the same canonical type. These two changes while being seemingly unrelated need to be bundled together to fix a number of issues in the existing test reference outputs because fixing the first one is needed to uncover the later issue. * src/abg-dwarf-reader.cc (add_or_update_union_type): Don't use the empty name of anonymous members in the lookup to ensure that all data members are unique. Rather, use the whole anonymous member itself for the lookup, just like is done to handle anonymous data member in classes/structs. * src/abg-reader.cc (build_union_decl): Likewise. * src/abg-ir.cc (get_generic_anonymous_internal_type_name): Define new static function. (get_type_name): For internal purposes, make the type name of all anonymous types of a given kind to be the same. This allows the internal representation of anonymous types which are based on type names to all be the same, so that they can be compared among themselves during type canonicalization. * tests/data/test-read-dwarf/test-PR26568-{1,2}.c: Source code of binary test input. * tests/data/test-read-dwarf/test-PR26568-{1,2}.o: New binary test input. * tests/data/test-read-dwarf/test-PR26568-{1,2}.o.abi: New reference test ouput. * tests/data/Makefile.am: Add the new test material above to source distribution. * tests/test-read-dwarf.cc (in_out_specs): Add the new binary test input above to this test harness. * tests/data/test-diff-dwarf-abixml/PR25409-librte_bus_dpaa.so.20.0.abi: Adjust. * tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise. * tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2020-09-16 15:49:53 +00:00
struct A {
union {
struct {
int x;
};
struct {
long y;
};
};
};
void fun(struct A * a) {
a->x = 0;
a->y = 0x0102030405060708ULL;
}