From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 7AA1B394844B for ; Tue, 12 May 2020 21:19:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7AA1B394844B X-ASG-Debug-ID: 1589318351-0c856e314b893940001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id Vh9o7D4oTOdHhtZD (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 12 May 2020 17:19:11 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by smtp.ebox.ca (Postfix) with ESMTP id 8A87E441B21; Tue, 12 May 2020 17:19:11 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-181-218.qc.cable.ebox.net[192.222.181.218] X-Barracuda-Apparent-Source-IP: 192.222.181.218 X-Barracuda-RBL-IP: 192.222.181.218 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 42/42] Share DWARF partial symtabs Date: Tue, 12 May 2020 17:18:24 -0400 X-ASG-Orig-Subj: [PATCH v2 42/42] Share DWARF partial symtabs Message-Id: <20200512211824.6834-43-simon.marchi@efficios.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200512210913.5593-1-simon.marchi@efficios.com> References: <20200512210913.5593-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1589318351 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 10900 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.81805 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-24.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 May 2020 21:19:15 -0000 From: Tom Tromey This changes the DWARF reader to share partial symtabs (or indices if they are available) across objfiles. This has a few parts. * If multiple objfiles backed by the same BFD can share partial symtabs (see below), a single dwarf2_per_bfd is created. It is stored in the per-bfd `dwarf2_per_bfd_bfd_data_key` registry. Multiple dwarf2_per_objfile objects will point to the same instance. The lifetime of these dwarf2_per_bfd objects is naturally handled. When all the objfiles using the BFD are destroyed, the BFD's refount drops to 0, which triggers the removal of the corresponding dwarf2_per_bfd object from the registry and its destruction. * If multiple objfiles backed by the same BFD can't share partial symtabs (see below), one dwarf2_per_bfd object is created for each objfile. Each dwarf2_per_objfile will point to their own instance of dwarf2_per_bfd. These instances of dwarf2_per_bfd are kept in a per-objfile registry, meaning that when the objfile gets destroyed, the dwarf2_per_bfd instance gets destroyed as well. * objfile::partial_symtabs is changed to be a shared_ptr again. This lets us stash a second reference in dwarf2_per_bfd; if the DWARF data is being shared, we can simply copy this value to the new objfile. * Two dwarf2_per_objfile objects backed by the same BFD may share a dwarf2_per_bfd instance if: * No other symbol reader has found symbols, and * No BFD section rqeuires relocation YYYY-MM-DD Tom Tromey YYYY-MM-DD Simon Marchi * objfiles.h (struct objfile) : Now a shared_ptr. * dwarf2/read.h (struct dwarf2_per_objfile) : New member. * dwarf2/read.c (dwarf2_per_bfd_bfd_data_key, dwarf2_per_bfd_objfile_data_key>: New globals. (dwarf2_has_info): Use shared dwarf2_per_bfd if possible. (dwarf2_get_section_info): Use get_dwarf2_per_objfile. (dwarf2_initialize_objfile): Consider cases where per_bfd can be shared. (dwarf2_build_psymtabs): Set objfile::partial_symtabs and short-circuit when sharing. (dwarf2_build_psymtabs): Set dwarf2_per_objfile::partial_symtabs. (dwarf2_psymtab::expand_psymtab): Use free_cached_comp_units. --- gdb/dwarf2/read.c | 105 +++++++++++++++++++++++++++++++++++++++------- gdb/dwarf2/read.h | 5 +++ gdb/objfiles.h | 2 +- 3 files changed, 97 insertions(+), 15 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3f93a51381f..2de4ead004f 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -105,7 +105,19 @@ static bool check_physname = false; /* When true, do not reject deprecated .gdb_index sections. */ static bool use_deprecated_index_sections = false; -static const struct objfile_key dwarf2_objfile_data_key; +/* This is used to store the data that is always per objfile. */ +static const objfile_key dwarf2_objfile_data_key; + +/* These are used to store the dwarf2_per_bfd objects. + + objfiles having the same BFD, which doesn't require relocations, are going to + share a dwarf2_per_bfd object, which is held in the _bfd_data_key version. + + Other objfiles are not going to share a dwarf2_per_bfd with any other + objfiles, so they'll have their own version kept in the _objfile_data_key + version. */ +static const struct bfd_key dwarf2_per_bfd_bfd_data_key; +static const struct objfile_key dwarf2_per_bfd_objfile_data_key; /* The "aclass" indices for various kinds of computed DWARF symbols. */ @@ -1853,9 +1865,30 @@ dwarf2_has_info (struct objfile *objfile, if (dwarf2_per_objfile == NULL) { - /* For now, each dwarf2_per_objfile owns its own dwarf2_per_bfd (no - sharing yet). */ - dwarf2_per_bfd *per_bfd = new dwarf2_per_bfd (objfile->obfd, names, can_copy); + dwarf2_per_bfd *per_bfd; + + /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD + doesn't require relocations and if there aren't partial symbols + from some other reader. */ + if (!objfile_has_partial_symbols (objfile) + && !gdb_bfd_requires_relocations (objfile->obfd)) + { + /* See if one has been created for this BFD yet. */ + per_bfd = dwarf2_per_bfd_bfd_data_key.get (objfile->obfd); + + if (per_bfd == nullptr) + { + /* No, create it now. */ + per_bfd = new dwarf2_per_bfd (objfile->obfd, names, can_copy); + dwarf2_per_bfd_bfd_data_key.set (objfile->obfd, per_bfd); + } + } + else + { + /* No sharing possible, create one specifically for this objfile. */ + per_bfd = new dwarf2_per_bfd (objfile->obfd, names, can_copy); + dwarf2_per_bfd_objfile_data_key.set (objfile, per_bfd); + } dwarf2_per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile, per_bfd); } @@ -2017,7 +2050,7 @@ dwarf2_get_section_info (struct objfile *objfile, asection **sectp, const gdb_byte **bufp, bfd_size_type *sizep) { - struct dwarf2_per_objfile *data = dwarf2_objfile_data_key.get (objfile); + struct dwarf2_per_objfile *data = get_dwarf2_per_objfile (objfile); struct dwarf2_section_info *info; /* We may see an objfile without any DWARF, in which case we just @@ -5874,6 +5907,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) { struct dwarf2_per_objfile *dwarf2_per_objfile = get_dwarf2_per_objfile (objfile); + dwarf2_per_bfd *per_bfd = dwarf2_per_objfile->per_bfd; /* If we're about to read full symbols, don't bother with the indices. In this case we also don't care if some other debug @@ -5881,20 +5915,28 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) expanded anyway. */ if ((objfile->flags & OBJF_READNOW)) { - dwarf2_per_objfile->per_bfd->using_index = 1; + /* When using READNOW, the using_index flag (set below) indicates that + PER_BFD was already initialized, when we loaded some other objfile. */ + if (per_bfd->using_index) + { + *index_kind = dw_index_kind::GDB_INDEX; + dwarf2_per_objfile->resize_symtabs (); + return true; + } + + per_bfd->using_index = 1; create_all_comp_units (dwarf2_per_objfile); create_all_type_units (dwarf2_per_objfile); - dwarf2_per_objfile->per_bfd->quick_file_names_table - = create_quick_file_names_table - (dwarf2_per_objfile->per_bfd->all_comp_units.size ()); + per_bfd->quick_file_names_table + = create_quick_file_names_table (per_bfd->all_comp_units.size ()); dwarf2_per_objfile->resize_symtabs (); - for (int i = 0; i < (dwarf2_per_objfile->per_bfd->all_comp_units.size () - + dwarf2_per_objfile->per_bfd->all_type_units.size ()); ++i) + for (int i = 0; i < (per_bfd->all_comp_units.size () + + per_bfd->all_type_units.size ()); ++i) { - dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->per_bfd->get_cutu (i); + dwarf2_per_cu_data *per_cu = per_bfd->get_cutu (i); - per_cu->v.quick = OBSTACK_ZALLOC (&dwarf2_per_objfile->per_bfd->obstack, + per_cu->v.quick = OBSTACK_ZALLOC (&per_bfd->obstack, struct dwarf2_per_cu_quick_data); } @@ -5905,6 +5947,24 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) return true; } + /* Was a debug names index already read when we processed an objfile sharing + PER_BFD? */ + if (per_bfd->debug_names_table != nullptr) + { + *index_kind = dw_index_kind::DEBUG_NAMES; + dwarf2_per_objfile->resize_symtabs (); + return true; + } + + /* Was a GDB index already read when we processed an objfile sharing + PER_BFD? */ + if (per_bfd->index_table != nullptr) + { + *index_kind = dw_index_kind::GDB_INDEX; + dwarf2_per_objfile->resize_symtabs (); + return true; + } + if (dwarf2_read_debug_names (dwarf2_per_objfile)) { *index_kind = dw_index_kind::DEBUG_NAMES; @@ -5945,6 +6005,16 @@ dwarf2_build_psymtabs (struct objfile *objfile) { struct dwarf2_per_objfile *dwarf2_per_objfile = get_dwarf2_per_objfile (objfile); + dwarf2_per_bfd *per_bfd = dwarf2_per_objfile->per_bfd; + + if (per_bfd->partial_symtabs != nullptr) + { + /* Partial symbols were already read, so now we can simply + attach them. */ + objfile->partial_symtabs = per_bfd->partial_symtabs; + dwarf2_per_objfile->resize_symtabs (); + return; + } init_psymbol_list (objfile, 1024); @@ -5966,6 +6036,12 @@ dwarf2_build_psymtabs (struct objfile *objfile) { exception_print (gdb_stderr, except); } + + /* Finish by setting the local reference to partial symtabs, so that + we don't try to read them again if reading another objfile with the same + BFD. If we can't in fact share, this won't make a difference anyway as + the dwarf2_per_bfd object won't be shared. */ + per_bfd->partial_symtabs = objfile->partial_symtabs; } /* Find the base address of the compilation unit for range lists and @@ -9014,9 +9090,10 @@ dwarf2_psymtab::expand_psymtab (struct objfile *objfile) { gdb_assert (!readin_p (objfile)); + dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); + free_cached_comp_units freer (per_objfile); expand_dependencies (objfile); - dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); dw2_do_instantiate_symtab (per_cu_data, per_objfile, false); gdb_assert (get_compunit_symtab (objfile) != nullptr); } diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 996cf55af22..53f0c7361a3 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -254,6 +254,11 @@ struct dwarf2_per_bfd /* CUs that are queued to be read. */ std::queue queue; + /* We keep a separate reference to the partial symtabs, in case we + are sharing them between objfiles. This is only set after + partial symbols have been read the first time. */ + std::shared_ptr partial_symtabs; + private: /* The total number of per_cu and signatured_type objects that have diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 0b47bd0c1e2..56ff52119dc 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -576,7 +576,7 @@ struct objfile /* The partial symbol tables. */ - std::unique_ptr partial_symtabs; + std::shared_ptr partial_symtabs; /* The object file's BFD. Can be null if the objfile contains only minimal symbols, e.g. the run time common symbols for SunOS4. */ -- 2.26.2