From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id E64393858C2C; Fri, 29 Apr 2022 20:26:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E64393858C2C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] De-duplicate .gdb_index X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 446fcb446f57dbb33728c3dbd5f092bca3ba3547 X-Git-Newrev: c7a73fa4dc7c7e9589b144e9ff9d9103b78ed362 Message-Id: <20220429202611.E64393858C2C@sourceware.org> Date: Fri, 29 Apr 2022 20:26:11 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Apr 2022 20:26:12 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc7a73fa4dc7c= 7e9589b144e9ff9d9103b78ed362 commit c7a73fa4dc7c7e9589b144e9ff9d9103b78ed362 Author: Tom Tromey Date: Mon Apr 25 11:20:36 2022 -0600 De-duplicate .gdb_index =20 This de-duplicates variables and types in .gdb_index, making the new index closer to what gdb generated before the new DWARF scanner series. Spot-checking the resulting index for gdb itself, it seems that the new scanner picks up some extra symbols not detected by the old one. I tested both the new and old versions of gdb on both new and old versions of the index, and startup time in all cases is roughly the same (it's worth noting that, for gdb itself, the index no longer provides any benefit over the DWARF scanner). So, I think this fixes the size issue with the new index writer. =20 Regression tested on x86-64 Fedora 34. Diff: --- gdb/dwarf2/index-write.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index e27c2b5fddd..62a7466bcfe 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1103,6 +1103,15 @@ write_cooked_index (cooked_index_vector *table, const cu_index_map &cu_index_htab, struct mapped_symtab *symtab) { + /* We track type names and only enter a given type once. */ + htab_up type_names (htab_create_alloc (10, htab_hash_string, htab_eq_str= ing, + nullptr, xcalloc, xfree)); + /* Same with variable names. However, if a type and variable share + a name, we want both, which is why there are two hash tables + here. */ + htab_up var_names (htab_create_alloc (10, htab_hash_string, htab_eq_stri= ng, + nullptr, xcalloc, xfree)); + for (const cooked_index_entry *entry : table->all_entries ()) { /* GDB never put linkage names into .gdb_index. The theory here @@ -1124,12 +1133,24 @@ write_cooked_index (cooked_index_vector *table, else if (entry->tag =3D=3D DW_TAG_variable || entry->tag =3D=3D DW_TAG_constant || entry->tag =3D=3D DW_TAG_enumerator) - kind =3D GDB_INDEX_SYMBOL_KIND_VARIABLE; + { + kind =3D GDB_INDEX_SYMBOL_KIND_VARIABLE; + void **slot =3D htab_find_slot (var_names.get (), name, INSERT); + if (*slot !=3D nullptr) + continue; + *slot =3D (void *) name; + } else if (entry->tag =3D=3D DW_TAG_module || entry->tag =3D=3D DW_TAG_common_block) kind =3D GDB_INDEX_SYMBOL_KIND_OTHER; else - kind =3D GDB_INDEX_SYMBOL_KIND_TYPE; + { + kind =3D GDB_INDEX_SYMBOL_KIND_TYPE; + void **slot =3D htab_find_slot (type_names.get (), name, INSERT); + if (*slot !=3D nullptr) + continue; + *slot =3D (void *) name; + } =20 add_index_entry (symtab, name, (entry->flags & IS_STATIC) !=3D 0, kind, it->second);