Bug 19126 - abidw segv on a dwz compressed version of r300_dri.so
authorDodji Seketeli <dodji@redhat.com>
Thu, 10 Dec 2015 13:18:46 +0000 (14:18 +0100)
committerDodji Seketeli <dodji@redhat.com>
Thu, 10 Dec 2015 15:47:18 +0000 (16:47 +0100)
commit0ec24168378d2649f58f7384faa9fd2ef72276ee
treec00c0a85d767d4475442402ff53a50a128937f5a
parent8c8df9d1ccb51c09ab3e0fae216732eb2d444ff7
Bug 19126 - abidw segv on a dwz compressed version of r300_dri.so

Suppose a declaration D (which locus is in a file F) is imported at an
offset offset of O1 into a compilation unit C1 and at an offset O2
(using DW_TAG_imported_unit) into a compilation unit C2.

When the DWARF reader creates the ABI artifact for D in O1, its
location is encoded by a location manager that is handled by C1.

At O2 (in C2) the ABI artifact for D (created at O1, in C1) is
re-used.  But then, to decode the location of D, the DWARF reader
wrongly uses the location manager that is handled by C2.  It should
use the location manager of C1, because that is the one used to encode
the location of D.

It picks the wrong location manager because it picks the wrong
translation unit for D. Right now, the translation unit for a given
declaration is the "current" translation unit at the moment the DIE
was being inspected.  And that is wrong when imported type units kick
in.

1/ More generally, each ABI artifact should be associated with its
translation unit, which is the current translation unit when the
artifact was created.  As there is just one copy of D, its translation
unit should always be the same.

2/ Also, the location should ensure that about the location manager used
to encode it is the same one used to decode it, so that this kind of
bug cannot arise.

This patch fixes the issue by doing 1/ and 2/.  The r300_dri.so test
case on which is was failing is not added to the test suite because
it's too big.  It was taking more than 55 minutes to have complete
abidw --abidiff complete on that binary, on my machine.  So I am going
to work on the performance side of things, I think.

* include/abg-ir.h (class location_manager): Forward declare it
before class location.
(location::loc_manager_): New data member.
(location::location): Take the location manager in one overload
and initialize the new loc_managers_ in all the overloads.
(location::get_location_manager): New getter.
(location::expand): New member function.
(location::*): Add API doc to all entry points.
(location_manager::expand_location): Take a const location.
(type_or_decl_base::set_corpus): Remove.
(type_or_decl_base::{get,set}_translation): New accessors.
(decl_base::{decl_base,get_location}): Take or return a reference
on location.
(scope_decl::scope_decl): Likewise.
(type_decl::type_decl): Likewise.
(namespace_decl::namespace_decl): Likewise.
(qualified_type_def::qualified_type_def): Likewise.
(pointer_type_def::pointer_type_def): Likewise.
(reference_type_def::reference_type_def): Likewise.
(array_type_def::subrange_type::{subrange_type,
get_location}): Likewise.
(enum_type_decl::enum_type_decl): Likewise.
(typedef_decl::typedef_decl): Likewise.
(var_decl::var_decl): Likewise.
(function_decl::function_decl): Likewise.
(function_decl::parameter::parameter): Likewise.
(template_decl::template_decl): Likewise.
(type_tparameter::type_tparameter): Likewise.
(non_type_tparameter::non_type_tparameter): Likewise.
(function_tdecl::function_tdecl): Likewise.
(class_tdecl::class_tdecl): Likewise.
(class_decl::class_decl): Likewise.
(class_decl::method_decl::method_decl): Likewise.
* src/abg-ir.cc (location::expand_location): Define new member
function.
(type_or_decl_base::priv::corpus_): Remove.
(type_or_decl_base::priv::translation_unit_): New data member.
(type_or_decl_base::priv::priv): Adjust.
(type_or_decl_base::set_corpus): Remove.
(type_or_decl_base::get_corpus): Adjust.
(type_or_decl_base::{get,set}_translation_unit): New member
functions.
(decl_base::priv::priv): Take a reference to location.
(decl_base::decl_base): Likewise.
(decl_base::get_location): Return a reference to location.
(location_manager::create_new_location): Adjust.
(location_manager::expand_location): Take a reference to location.
(translation_unit::get_global_scope()): Adjust.
(translation_unit::bind_function_type_life_time): Likewise.
(scope_decl::{add,insert}_member_decl): Adjust.
(get_translation_unit): Likewise.
(type_decl::type_decl): Take a reference to location.
(namespace_decl::namespace_decl): Likewise.
(qualified_type_def::qualified_type_def): Likewise.
(pointer_type_def::pointer_type_def): Likewise.
(reference_type_def::reference_type_def): Likewise.
(array_type_def::subrange_type::priv::priv): Likewise.
(array_type_def::subrange_type::{subrange_type,
get_location}): Likewise.
(enum_type_decl::enum_type_decl): Likewise.
(typedef_decl::typedef_decl): Likewise.
(var_decl::var_decl): Likewise.
(function_decl::function_decl): Likewise.
(function_decl::parameter::parameter): Likewise.
(template_decl::template_decl): Likewise.
(type_tparameter::type_tparameter): Likewise.
(non_type_tparameter::non_type_tparameter): Likewise.
(function_tdecl::function_tdecl): Likewise.
(class_tdecl::class_tdecl): Likewise.
(class_decl::class_decl): Likewise.
(class_decl::method_decl::method_decl): Likewise.
* src/abg-writer.cc (write_location): Take a reference to
location and adjust.
(write_array_type_def, write_function_decl, dump_decl_location):
Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
include/abg-ir.h
src/abg-ir.cc
src/abg-writer.cc