From 275e6d46a4036d2d278358da842e5e44bb2c4ead Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Tue, 18 May 2021 12:18:23 -0700 Subject: [PATCH] Make forward reference DIEs cross compilation units. Before this change, forward_ref_die_to_func is always empty. Because forward reference DIEs could cross compilation units, forward_ref_die_to_func is moved into FilePrivate. By using "grep "name omitted" sym | wc -l", the number of functions with no name is reduced from 26951 to 203 if forward reference only is allowed within CU. It's reduced from 203 to 6 if crossing compilation units is allowed. Change-Id: Ie2a457abfc0c4d8e68fe0fa595a27ea4abf33a76 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2904093 Reviewed-by: Mike Frysinger --- src/common/dwarf_cu_to_module.cc | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/common/dwarf_cu_to_module.cc b/src/common/dwarf_cu_to_module.cc index 95e79357..1964550f 100644 --- a/src/common/dwarf_cu_to_module.cc +++ b/src/common/dwarf_cu_to_module.cc @@ -126,6 +126,10 @@ struct DwarfCUToModule::FilePrivate { SpecificationByOffset specifications; AbstractOriginByOffset origins; + + // Keep a list of forward references from DW_AT_abstract_origin and + // DW_AT_specification attributes so names can be fixed up. + std::map forward_ref_die_to_func; }; DwarfCUToModule::FileContext::FileContext(const string& filename, @@ -265,10 +269,6 @@ struct DwarfCUToModule::CUContext { // // Destroying this destroys all the functions this vector points to. vector functions; - - // Keep a list of forward references from DW_AT_abstract_origin and - // DW_AT_specification attributes so names can be fixed up. - std::map forward_ref_die_to_func; }; // Information about the context of a particular DIE. This is for @@ -642,8 +642,11 @@ void DwarfCUToModule::FuncHandler::Finish() { // to be processed, and fix up the name of the appropriate Module::Function. // "name_" will have already been fixed up in EndAttributes(). if (!name_.empty()) { - auto iter = cu_context_->forward_ref_die_to_func.find(offset_); - if (iter != cu_context_->forward_ref_die_to_func.end()) + auto iter = + cu_context_->file_context->file_private_->forward_ref_die_to_func.find( + offset_); + if (iter != + cu_context_->file_context->file_private_->forward_ref_die_to_func.end()) iter->second->name = name_; } @@ -708,14 +711,9 @@ void DwarfCUToModule::FuncHandler::Finish() { // description is just empty debug data and should just be discarded. cu_context_->functions.push_back(func.release()); if (forward_ref_die_offset_ != 0) { - auto iter = - cu_context_->forward_ref_die_to_func.find(forward_ref_die_offset_); - if (iter == cu_context_->forward_ref_die_to_func.end()) { - cu_context_->reporter->UnknownSpecification(offset_, - forward_ref_die_offset_); - } else { - iter->second = cu_context_->functions.back(); - } + cu_context_->file_context->file_private_ + ->forward_ref_die_to_func[forward_ref_die_offset_] = + cu_context_->functions.back(); } } } else if (inline_) {