2020-05-29 14:26:04 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-01-17 18:41:51 +00:00
|
|
|
// -*- Mode: C++ -*-
|
|
|
|
//
|
|
|
|
// Author: Ondrej Oprala
|
|
|
|
|
|
|
|
/// @file
|
|
|
|
///
|
|
|
|
/// This program tests the annotation capabilities of the library.
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include "abg-tools-utils.h"
|
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
|
|
using std::cerr;
|
|
|
|
using std::string;
|
2021-11-11 05:53:42 +00:00
|
|
|
using abigail::tests::emit_test_status_and_update_counters;
|
|
|
|
using abigail::tests::emit_test_summary;
|
2017-01-17 18:41:51 +00:00
|
|
|
|
|
|
|
struct InOutSpec
|
|
|
|
{
|
|
|
|
const char* in_elf_path;
|
|
|
|
const char* in_report_path;
|
|
|
|
const char* out_report_path;
|
|
|
|
};
|
|
|
|
|
|
|
|
InOutSpec in_out_specs[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test0",
|
|
|
|
"data/test-annotate/test0.abi",
|
|
|
|
"output/test-annotate/test0.abi"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test1",
|
|
|
|
"data/test-annotate/test1.abi",
|
|
|
|
"output/test-annotate/test1.abi"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test2.so",
|
|
|
|
"data/test-annotate/test2.so.abi",
|
|
|
|
"output/test-annotate/test2.so.abi"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test3.so",
|
|
|
|
"data/test-annotate/test3.so.abi",
|
|
|
|
"output/test-annotate/test3.so.abi"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test4.so",
|
|
|
|
"data/test-annotate/test4.so.abi",
|
|
|
|
"output/test-annotate/test4.so.abi"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test5.o",
|
|
|
|
"data/test-annotate/test5.o.abi",
|
|
|
|
"output/test-annotate/test5.o.abi"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test6.so",
|
|
|
|
"data/test-annotate/test6.so.abi",
|
|
|
|
"output/test-annotate/test6.so.abi"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test7.so",
|
|
|
|
"data/test-annotate/test7.so.abi",
|
|
|
|
"output/test-annotate/test7.so.abi"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test8-qualified-this-pointer.so",
|
|
|
|
"data/test-annotate/test8-qualified-this-pointer.so.abi",
|
|
|
|
"output/test-annotate/test8-qualified-this-pointer.so.abi"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test13-pr18894.so",
|
|
|
|
"data/test-annotate/test13-pr18894.so.abi",
|
|
|
|
"output/test-annotate/test13-pr18894.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test14-pr18893.so",
|
|
|
|
"data/test-annotate/test14-pr18893.so.abi",
|
|
|
|
"output/test-annotate/test14-pr18893.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test15-pr18892.so",
|
|
|
|
"data/test-annotate/test15-pr18892.so.abi",
|
|
|
|
"output/test-annotate/test15-pr18892.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test17-pr19027.so",
|
|
|
|
"data/test-annotate/test17-pr19027.so.abi",
|
|
|
|
"output/test-annotate/test17-pr19027.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so",
|
|
|
|
"data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi",
|
|
|
|
"output/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so",
|
|
|
|
"data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi",
|
|
|
|
"output/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so",
|
|
|
|
"data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi",
|
|
|
|
"output/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/test21-pr19092.so",
|
|
|
|
"data/test-annotate/test21-pr19092.so.abi",
|
|
|
|
"output/test-annotate/test21-pr19092.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/libtest23.so",
|
|
|
|
"data/test-annotate/libtest23.so.abi",
|
|
|
|
"output/test-annotate/libtest23.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/libtest24-drop-fns.so",
|
|
|
|
"data/test-annotate/libtest24-drop-fns.so.abi",
|
|
|
|
"output/test-annotate/libtest24-drop-fns.so.abi",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data/test-read-dwarf/libtest24-drop-fns.so",
|
|
|
|
"data/test-annotate/libtest24-drop-fns-2.so.abi",
|
|
|
|
"output/test-annotate/libtest24-drop-fns-2.so.abi",
|
|
|
|
},
|
Handle several member anonymous types of the same kind
When there are several anonymous types (e.g, anonymous classes, unions
or enums) in a given class or union, libabigail's internals do
struggle.
An anonymous class, for instance, is named __anonymous_struct__. When
there are more than one of these inside a given class, then we can't
name and look them up, because they all have the same name.
Incidentally, when add_or_update_class_type completes a class type
that was initially constructed before, it fails to determine that an
anonymous member type of that class was already present in that
context. It thus wrongly duplicates anonymous structs/unions/enums in
there and that leads to spurious textual (abixml) representation
differences later, where duplicated anonymous member types would
appear intermittently, depending on the order in which the class was
built.
This patch addresses this general issue by naming anonymous member
types in a way that allows several of them to exist. That is, if there
are two anonymous structs in a class, they are going to be named
__anonymous_struct__ and __anonymous_struct__1. We do follow a
similar scheme for anonymous unions and enums. This is handled by the
DWARF reader that builds the internal representation.
While looking at this issue, I also fixed a tangent bug; some DWARF
emitters wrongly *define* types in the scope of a
DW_TAG_subroutine_type or DW_TAG_array_type. We handle that by
actually defining those types in the scope of that subroutine or
array. But then it appears that if that scope itself a class and if
the type defined is an anonymous type, then putting that anonymous
type in the class scope might interfere with the *naming* of the
existing legit anonymous types of that scope. I decided to put those
anonymous types in the containing namespace instead. We'll see how
that goes in real time use.
The patch also updates lots of existing tests and adds a new one.
* include/abg-ir.h
(class_or_union::get_num_anonymous_member_{classes, unions,
enums}): Declare new member functions.
* src/abg-dwarf-reader.cc (get_internal_anonynous_die_base_name)
(build_internal_anonymous_die_name)
(get_internal_anonymous_die_name, is_anonymous_type_die): Define
new static functions.
(die_qualified_type_name): Use the new
get_internal_anonymous_die_name.
(get_scope_for_die): Fix this to put anonymous types that were
wrongly emitted into the scope of DW_TAG_subroutine_type or
DW_TAG_array_type by buggy DWARF emitters into the enclosing
namespace, rather than into the enclosing class/union.
(build_enum_type): Take the scope of the enum to have a chance to
properly name potential anonymous enums.
(lookup_class_typedef_or_enum_type_from_corpus): Take an anonymous
member type index for when the DIE we are lookup up represents an
anonymous type. Support proper building of the internal anonymous
name of the anonymous type we are lookup up.
(add_or_update_class_type): Use the new
get_internal_anonynous_die_base_name and
build_internal_anonymous_die_name functions. Support making sure
that the anonymous member type we are adding to the class wasn't
already there, especially for cases where we are updating a class
type.
(add_or_update_union_type): Use the new
get_internal_anonynous_die_base_name and
build_internal_anonymous_die_name functions.
(build_ir_node_from_die): Adjust the use of build_enum_type to
pass it the scope of the enum type we are building.
* src/abg-ir.cc (lookup_union_type): Add a new overload.
(lookup_class_or_typedef_type): Use the new overload of
lookup_union_type above to support looking up union types too.
(class_or_union::get_num_anonymous_member_{classes, unions,
enums}): Define new member functions.
* src/abg-reporter-priv.cc (represent): Detect when anonymous
types of anonymous data members have their internal names change,
probably because anonymous member types were inserted in the scope.
* tests/data/Makefile.am: Add the new test-anonymous-members-0.*
test input files to the source distribution.
* tests/data/test-annotate/test-anonymous-members-0.cc: New test
input file.
* tests/data/test-annotate/test-anonymous-members-0.o: Likewise.
* tests/data/test-annotate/test-anonymous-members-0.o.abi: Likewise.
* tests/data/test-annotate/test17-pr19027.so.abi: Adjust.
* 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/test21-pr19092.so.abi: Likewise.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
Likewise.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt:
Likewise.
* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
Likewise.
* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
* tests/data/test-read-dwarf/test12-pr18844.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/test21-pr19092.so.abi: Likewise.
* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
Likewise.
* tests/test-annotate.cc (int_out_specs): Add the new test inputs
to this test harness.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2019-05-07 08:22:29 +00:00
|
|
|
{
|
|
|
|
"data/test-annotate/test-anonymous-members-0.o",
|
|
|
|
"data/test-annotate/test-anonymous-members-0.o.abi",
|
|
|
|
"output/test-annotate/test-anonymous-members-0.o.abi",
|
|
|
|
},
|
2017-01-17 18:41:51 +00:00
|
|
|
// This should be the last entry.
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
using abigail::tests::get_src_dir;
|
|
|
|
using abigail::tests::get_build_dir;
|
|
|
|
using abigail::tools_utils::ensure_parent_dir_created;
|
|
|
|
|
2021-11-11 05:53:42 +00:00
|
|
|
unsigned int total_count = 0, passed_count = 0, failed_count = 0;
|
|
|
|
|
2017-01-17 18:41:51 +00:00
|
|
|
string in_elf_path, ref_report_path, out_report_path;
|
|
|
|
string abidw;
|
|
|
|
|
|
|
|
abidw = string(get_build_dir()) + "/tools/abidw "
|
2017-11-02 11:46:32 +00:00
|
|
|
"--annotate --no-corpus-path";
|
2017-01-17 18:41:51 +00:00
|
|
|
for (InOutSpec* s = in_out_specs; s->in_elf_path; ++s)
|
|
|
|
{
|
2021-11-11 05:53:42 +00:00
|
|
|
bool is_ok = true;
|
2017-01-17 18:41:51 +00:00
|
|
|
in_elf_path = string(get_src_dir()) + "/tests/" + s->in_elf_path;
|
|
|
|
ref_report_path = string(get_src_dir()) + "/tests/" + s->in_report_path;
|
|
|
|
out_report_path =
|
|
|
|
string(get_build_dir()) + "/tests/" + s->out_report_path;
|
|
|
|
if (!ensure_parent_dir_created(out_report_path))
|
|
|
|
{
|
|
|
|
cerr << "could not create parent directory for "
|
|
|
|
<< out_report_path;
|
|
|
|
is_ok = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
string cmd = abidw + " " + in_elf_path + " > " + out_report_path;
|
|
|
|
|
|
|
|
bool abidw_ok = true;
|
|
|
|
if (system(cmd.c_str()))
|
|
|
|
abidw_ok = false;
|
|
|
|
|
|
|
|
if (abidw_ok)
|
|
|
|
{
|
2021-11-11 05:53:42 +00:00
|
|
|
string diff_cmd =
|
|
|
|
"diff -u " + ref_report_path + " " + out_report_path;
|
|
|
|
if (system(diff_cmd.c_str()))
|
2017-01-17 18:41:51 +00:00
|
|
|
is_ok &=false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
is_ok &= false;
|
|
|
|
}
|
2021-11-11 05:53:42 +00:00
|
|
|
|
|
|
|
emit_test_status_and_update_counters(is_ok, cmd, passed_count,
|
|
|
|
failed_count, total_count);
|
2017-01-17 18:41:51 +00:00
|
|
|
}
|
|
|
|
|
2021-11-11 05:53:42 +00:00
|
|
|
emit_test_summary(total_count, passed_count, failed_count);
|
|
|
|
|
|
|
|
return failed_count;
|
2017-01-17 18:41:51 +00:00
|
|
|
}
|