From: Simon Marchi Date: Mon, 12 May 2025 19:09:44 +0000 (-0400) Subject: gdb/dwarf: allocate DWP dwarf2_section_info with new X-Git-Tag: binutils-2_45~512 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=e95749bd0d5579d1e87eaef0d667f23591bf3521;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: allocate DWP dwarf2_section_info with new For the same reason as explained in the previous patch (allocations on obstacks aren't thread-safe), change the allocation of dwarf2_section_info object for dwo files within dwp files to use "new". The dwo_file::section object is not always owned by the dwo_file, so introduce a new "dwo_file::section_holder" object that is only set when the dwo_file owns the dwarf2_section_info. Change-Id: I74c4608573c7a435bf3dadb83f96a805d21798a2 Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3d4e4a02375..b1849b9b071 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -299,6 +299,9 @@ struct dwo_unit /* The section this CU/TU lives in, in the DWO file. */ dwarf2_section_info *section = nullptr; + /* This is set if SECTION is owned by this dwo_unit. */ + dwarf2_section_info_up section_holder; + /* Same as dwarf2_per_cu::{sect_off,length} but in the DWO section. */ sect_offset sect_off {}; unsigned int length = 0; @@ -6938,7 +6941,8 @@ create_dwo_unit_in_dwp_v1 (dwarf2_per_bfd *per_bfd, auto dwo_unit = std::make_unique (); dwo_unit->dwo_file = dwo_file; dwo_unit->signature = signature; - dwo_unit->section = XOBNEW (&per_bfd->obstack, struct dwarf2_section_info); + dwo_unit->section_holder = std::make_unique (); + dwo_unit->section = dwo_unit->section_holder.get (); *dwo_unit->section = sections.info_or_types; /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */ @@ -7143,7 +7147,8 @@ create_dwo_unit_in_dwp_v2 (dwarf2_per_bfd *per_bfd, auto dwo_unit = std::make_unique (); dwo_unit->dwo_file = dwo_file; dwo_unit->signature = signature; - dwo_unit->section = XOBNEW (&per_bfd->obstack, struct dwarf2_section_info); + dwo_unit->section_holder = std::make_unique (); + dwo_unit->section = dwo_unit->section_holder.get (); *dwo_unit->section = create_dwp_v2_or_v5_section (per_bfd, is_debug_types diff --git a/gdb/dwarf2/section.h b/gdb/dwarf2/section.h index b9d3c31453f..fd6e34d3faa 100644 --- a/gdb/dwarf2/section.h +++ b/gdb/dwarf2/section.h @@ -112,4 +112,6 @@ struct dwarf2_section_info bool is_virtual; }; +using dwarf2_section_info_up = std::unique_ptr; + #endif /* GDB_DWARF2_SECTION_H */