]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: allocate DWP dwarf2_section_info with new
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 12 May 2025 19:09:44 +0000 (15:09 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 23 May 2025 15:12:53 +0000 (11:12 -0400)
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 <tom@tromey.com>
gdb/dwarf2/read.c
gdb/dwarf2/section.h

index 3d4e4a02375f25009c6698bac5c08b5b60b1e769..b1849b9b071d34645cbcc2b9a74c0f0487e51bab 100644 (file)
@@ -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<struct dwo_unit> ();
   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<dwarf2_section_info> ();
+  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<struct dwo_unit> ();
   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<dwarf2_section_info> ();
+  dwo_unit->section = dwo_unit->section_holder.get ();
   *dwo_unit->section = create_dwp_v2_or_v5_section
                         (per_bfd,
                          is_debug_types
index b9d3c31453f2a2ee3d477e95be8498ba4a2f450c..fd6e34d3faaa0f1e05f738517d1c31aa46b20f41 100644 (file)
@@ -112,4 +112,6 @@ struct dwarf2_section_info
   bool is_virtual;
 };
 
+using dwarf2_section_info_up = std::unique_ptr<dwarf2_section_info>;
+
 #endif /* GDB_DWARF2_SECTION_H */