[PATCH v2] dwp: Supports the analysis of DWO_id for Dwarf-5.

Sockke liuke.gehry@bytedance.com
Tue Jun 10 06:43:50 GMT 2025


Original patch: https://inbox.sourceware.org/binutils/20250519101018.1280986-1-liuke.gehry@bytedance.com/T/#t
Create index information for dwo id in dwarf5.

Signed-off-by: Sockke <liuke.gehry@bytedance.com>
---
 gold/dwarf_reader.cc | 7 +++++++
 gold/dwarf_reader.h  | 9 ++++++++-
 gold/dwp.cc          | 2 ++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gold/dwarf_reader.cc b/gold/dwarf_reader.cc
index a760f2745d5..fefa73c83aa 100644
--- a/gold/dwarf_reader.cc
+++ b/gold/dwarf_reader.cc
@@ -1582,6 +1582,13 @@ Dwarf_info_reader::do_parse()
 	  pinfo += this->offset_size_;
 	}
 
+      // DWARF 5: Read the DWO id (8 bytes).
+      if (this->cu_version_ >= 5)
+	{
+	  this->cu_signature_ = elfcpp::Swap_unaligned<64, big_endian>::readval(pinfo);
+	  pinfo += 8;
+	}
+
       // Read the .debug_abbrev table.
       this->abbrev_table_.read_abbrevs(this->object_, abbrev_shndx,
 				       abbrev_offset);
diff --git a/gold/dwarf_reader.h b/gold/dwarf_reader.h
index 4848d7e118c..1d965a3faa5 100644
--- a/gold/dwarf_reader.h
+++ b/gold/dwarf_reader.h
@@ -712,7 +712,7 @@ class Dwarf_info_reader
       symtab_size_(symtab_size), shndx_(shndx), reloc_shndx_(reloc_shndx),
       reloc_type_(reloc_type), abbrev_shndx_(0), string_shndx_(0),
       buffer_(NULL), buffer_end_(NULL), cu_offset_(0), cu_length_(0),
-      offset_size_(0), address_size_(0), cu_version_(0),
+      offset_size_(0), address_size_(0), cu_version_(0), cu_signature_(0),
       abbrev_table_(), ranges_table_(this),
       reloc_mapper_(NULL), string_buffer_(NULL), string_buffer_end_(NULL),
       owns_string_buffer_(false), string_output_section_offset_(0)
@@ -877,6 +877,11 @@ class Dwarf_info_reader
   reset_relocs(uint64_t checkpoint)
   { this->reloc_mapper_->reset(checkpoint); }
 
+  // Return the DWO id in Dwarf5.
+  uint64_t
+  get_cu_signature() const
+  { return this->cu_signature_; }
+
  private:
   // Print a warning about a corrupt debug section.
   void
@@ -940,6 +945,8 @@ class Dwarf_info_reader
   unsigned int address_size_;
   // Compilation unit version number.
   unsigned int cu_version_;
+  // Compilation unit DWO id in Dwarf5.
+  uint64_t cu_signature_;
   // Abbreviations table for current compilation unit.
   Dwarf_abbrev_table abbrev_table_;
   // Ranges table for the current compilation unit.
diff --git a/gold/dwp.cc b/gold/dwp.cc
index a0769285ea9..0bed9cd4869 100644
--- a/gold/dwp.cc
+++ b/gold/dwp.cc
@@ -2243,6 +2243,8 @@ Unit_reader::visit_compilation_unit(off_t, off_t cu_length, Dwarf_die* die)
 
   Unit_set* unit_set = new Unit_set();
   unit_set->signature = die->uint_attribute(elfcpp::DW_AT_GNU_dwo_id);
+  if (unit_set->signature == 0)
+    unit_set->signature = this->get_cu_signature();
   for (unsigned int i = elfcpp::DW_SECT_ABBREV; i <= elfcpp::DW_SECT_MAX; ++i)
     unit_set->sections[i] = this->sections_[i];
 
-- 
2.20.1



More information about the Binutils mailing list