From patchwork Fri Oct 25 19:10:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35347 Received: (qmail 102449 invoked by alias); 25 Oct 2019 19:10:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 102389 invoked by uid 89); 25 Oct 2019 19:10:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 Oct 2019 19:10:16 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 0C3652105B; Fri, 25 Oct 2019 15:10:14 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 84D5820EAD; Fri, 25 Oct 2019 15:10:08 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 6CBB7238BA; Fri, 25 Oct 2019 15:10:08 -0400 (EDT) X-Gerrit-PatchSet: 4 Date: Fri, 25 Oct 2019 15:10:08 -0400 From: "Sourceware to Gerrit sync (Code Review)" To: Christian Biesinger , gdb-patches@sourceware.org Cc: Tom Tromey , Simon Marchi , Luis Machado Auto-Submitted: auto-generated X-Gerrit-MessageType: merged Subject: [pushed] Don't make an extra copy + allocation of the demangled name X-Gerrit-Change-Id: Ie6ad50e1e1e73509f55d756f0a437897bb93e3b0 X-Gerrit-Change-Number: 132 X-Gerrit-ChangeURL: X-Gerrit-Commit: 5396ae1717ade2dbbdb73790eafcdd885045860b In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, simon.marchi@polymtl.ca, tromey@sourceware.org, luis.machado@linaro.org, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Message-Id: <20191025191008.6CBB7238BA@gnutoolchain-gerrit.osci.io> Sourceware to Gerrit sync has submitted this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/132 ...................................................................... Don't make an extra copy + allocation of the demangled name We can just keep around the malloc()-ed name we got from bfd and free it later. gdb/ChangeLog: 2019-10-25 Christian Biesinger * symtab.c (struct demangled_name_entry): Change demangled name to a unique_xmalloc_ptr, now that we don't allocate it as part of the struct anymore. (symbol_set_names): No longer obstack allocate + copy the demangled name, just store the allocated name from bfd. Change-Id: Ie6ad50e1e1e73509f55d756f0a437897bb93e3b0 --- M gdb/ChangeLog M gdb/symtab.c 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 84fb9aa..55c4647 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2019-10-25 Christian Biesinger + + * symtab.c (struct demangled_name_entry): Change demangled name + to a unique_xmalloc_ptr, now that we don't allocate it as + part of the struct anymore. + (symbol_set_names): No longer obstack allocate + copy the demangled + name, just store the allocated name from bfd. + 2019-10-25 Tom Tromey * dwarf2-frame.c (dwarf2_cie_table): Now a typedef. diff --git a/gdb/symtab.c b/gdb/symtab.c index 160a4c0..adf9e08 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -723,7 +723,7 @@ gdb::string_view mangled; enum language language; - char demangled[1]; + gdb::unique_xmalloc_ptr demangled; }; /* Hash function for the demangled name hash. */ @@ -839,7 +839,7 @@ { /* In Ada, we do the symbol lookups using the mangled name, so we can save some space by not storing the demangled name. */ - if (!copy_name) + if (!copy_name && linkage_name_copy == linkage_name) gsymbol->name = linkage_name; else { @@ -880,20 +880,17 @@ if (*slot == NULL /* A C version of the symbol may have already snuck into the table. This happens to, e.g., main.init (__go_init_main). Cope. */ - || (gsymbol->language == language_go - && (*slot)->demangled[0] == '\0')) + || (gsymbol->language == language_go && (*slot)->demangled == nullptr)) { - char *demangled_name_ptr - = symbol_find_demangled_name (gsymbol, linkage_name_copy); - gdb::unique_xmalloc_ptr demangled_name (demangled_name_ptr); - int demangled_len = demangled_name ? strlen (demangled_name.get ()) : 0; + gdb::unique_xmalloc_ptr demangled_name_ptr + (symbol_find_demangled_name (gsymbol, linkage_name_copy)); /* Suppose we have demangled_name==NULL, copy_name==0, and linkage_name_copy==linkage_name. In this case, we already have the mangled name saved, and we don't have a demangled name. So, you might think we could save a little space by not recording this in the hash table at all. - + It turns out that it is actually important to still save such an entry in the hash table, because storing this name gives us better bcache hit rates for partial symbols. */ @@ -902,42 +899,33 @@ *slot = ((struct demangled_name_entry *) obstack_alloc (&per_bfd->storage_obstack, - offsetof (struct demangled_name_entry, demangled) - + demangled_len + 1)); + sizeof (demangled_name_entry))); new (*slot) demangled_name_entry (gdb::string_view (linkage_name, len)); } else { - char *mangled_ptr; - /* If we must copy the mangled name, put it directly after - the demangled name so we can have a single - allocation. */ + the struct so we can have a single allocation. */ *slot = ((struct demangled_name_entry *) obstack_alloc (&per_bfd->storage_obstack, - offsetof (struct demangled_name_entry, demangled) - + len + demangled_len + 2)); - mangled_ptr = &((*slot)->demangled[demangled_len + 1]); + sizeof (demangled_name_entry) + len + 1)); + char *mangled_ptr = reinterpret_cast (*slot + 1); strcpy (mangled_ptr, linkage_name_copy); new (*slot) demangled_name_entry (gdb::string_view (mangled_ptr, len)); } + (*slot)->demangled = std::move (demangled_name_ptr); (*slot)->language = gsymbol->language; - - if (demangled_name != NULL) - strcpy ((*slot)->demangled, demangled_name.get ()); - else - (*slot)->demangled[0] = '\0'; } else if (gsymbol->language == language_unknown || gsymbol->language == language_auto) gsymbol->language = (*slot)->language; gsymbol->name = (*slot)->mangled.data (); - if ((*slot)->demangled[0] != '\0') - symbol_set_demangled_name (gsymbol, (*slot)->demangled, + if ((*slot)->demangled != nullptr) + symbol_set_demangled_name (gsymbol, (*slot)->demangled.get (), &per_bfd->storage_obstack); else symbol_set_demangled_name (gsymbol, NULL, &per_bfd->storage_obstack);