[gdb/symtab] Don't write .gdb_index symbol table with empty entries
authorTom de Vries <tdevries@suse.de>
Fri, 27 Aug 2021 15:14:49 +0000 (17:14 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 27 Aug 2021 15:14:49 +0000 (17:14 +0200)
When comparing the sizes of the index files generated for shlib
outputs/gdb.dwarf2/dw2-zero-range/shr1.sl, I noticed a large difference
between .debug_names:
...
$ gdb -q -batch $shlib -ex "save gdb-index -dwarf-5 ."
$ du -b -h shr1.sl.debug_names shr1.sl.debug_str
61      shr1.sl.debug_names
0       shr1.sl.debug_str
...
and .gdb_index:
...
$ gdb -q -batch $shlib -ex "save gdb-index ."
$ du -b -h shr1.sl.gdb-index
8.2K    shr1.sl.gdb-index
...

The problem is that the .gdb_index contains a non-empty symbol table with only
empty entries.

Fix this by making the symbol table empty, such that we have instead:
...
$ du -b -h shr1.sl.gdb-index
184     shr1.sl.gdb-index
...

Tested on x86_64-linux.

gdb/dwarf2/index-write.c

index 4e00c716d910a5e501aac78c86ce66b2bfa23f43..5de07a6c07b490e15bfa8c06b8c29630609f1909 100644 (file)
@@ -1385,6 +1385,9 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file,
   uniquify_cu_indices (&symtab);
 
   data_buf symtab_vec, constant_pool;
+  if (symtab.n_elements == 0)
+    symtab.data.resize (0);
+
   write_hash_table (&symtab, symtab_vec, constant_pool);
 
   write_gdbindex_1(out_file, objfile_cu_list, types_cu_list, addr_vec,