Bug 15646 - gold-generated .gdb_index has duplicated symbols that gdb-generated index doesn't
Summary: gold-generated .gdb_index has duplicated symbols that gdb-generated index doe...
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
Depends on:
Reported: 2013-06-18 22:32 UTC by dje
Modified: 2020-05-28 15:26 UTC (History)
2 users (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description dje 2013-06-18 22:32:44 UTC
The gdb-generated .gdb_index doesn't have duplicate entries in the symbol table for classes and namespaces (gdb's .gdb_index is based on its partial symbols, and gdb only keeps one copy of global partial syms).

The gold-generated .gdb_index does have duplicate entries for classes and namespaces.  This causes performance issues in gdb.
e.g. "break foo::misspelled" will expand the debug info for every CU recorded for "foo" in .gdb_index.


namespace N1
  class C1
    static void baz () {}

#include "foo.h"

namespace N1
  void foo () { C1::baz (); }

main ()
  return 0;

#include "namespace-n.h"

namespace N1
  void bar () { C1::baz (); }

The gold generated index has:

[721] N1::C1::baz:
        2 [global function]
        3 [global function]
[759] N1:
        2 [global type]
        3 [global type]
[961] N1::C1:
        2 [global type]
        3 [global type]

The gdb generated index has:

[721] N1::C1::baz: 2 [global function]
[759] N1: T0 [global type]
[961] N1::C1: T0 [global type]
Comment 1 dje 2013-11-12 18:03:14 UTC
Checked in this workaround in gdb:

Comment 2 Martin Richtarsky 2018-04-09 14:04:05 UTC
I found this bug while debugging another issue I had with gdb, described here:

Any idea why my problem is not resolved by the workaround pushed here? Could the workaround be extended to also handle the other case?

Also, it would be great if the gold index could be made more compatible, which is the scope of this bug I guess.

Best regards,
Comment 3 Martin Richtarsky 2018-05-02 08:29:03 UTC
Retested with binutils-2.29, same issue.
Comment 4 cvs-commit@gcc.gnu.org 2020-05-26 09:35:35 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:


commit 40d22035a7fc239ac1e944b75a2e3ee9029d1b76
Author: Tom de Vries <tdevries@suse.de>
Date:   Tue May 26 11:35:32 2020 +0200

    [gdb/testsuite] Add test-case gold-gdb-index.exp
    There's a PR binutils/15646 - "gold-generated .gdb_index has duplicated
    symbols that gdb-generated index doesn't", and gdb contains a workaround,
    added in commit 8943b87476 "Work around gold/15646".
    Add a test-case testing this workaround.
    Tested on x86_64-linux.
    2020-05-26  Tom de Vries  <tdevries@suse.de>
            * gdb.base/gold-gdb-index-2.c: New test.
            * gdb.base/gold-gdb-index.c: New test.
            * gdb.base/gold-gdb-index.exp: New file.
            * gdb.base/gold-gdb-index.h: New test.
Comment 5 cvs-commit@gcc.gnu.org 2020-05-28 15:26:26 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:


commit f030440daa989ae3dadc1fa4342cfa16d690db3c
Author: Tom de Vries <tdevries@suse.de>
Date:   Thu May 28 17:26:22 2020 +0200

    [gdb/symtab] Make gold index workaround more precise
    There's a PR gold/15646 - "gold-generated .gdb_index has duplicated
    symbols that gdb-generated index doesn't", that causes gold to generate
    duplicate symbols in the index.
    F.i., a namespace N1 declared in a header file can be listed for two CUs that
    include the header file:
    [759] N1:
            2 [global type]
            3 [global type]
    This causes a gdb performance problem: f.i. when attempting to set a
    breakpoint on a non-existing function N1::misspelled, the symtab for both CUs
    will be expanded.
    Gdb contains a workaround for this, added in commit 8943b87476 "Work around
    gold/15646", that skips duplicate global symbols in the index.
    However, the workaround does not check for the symbol kind ("type" in the
    example above).
    Make the workaround more precise by limiting it to symbol kind "type".
    Tested on x86_64-linux, with target boards cc-with-gdb-index and
    2020-05-28  Tom de Vries  <tdevries@suse.de>
            * dwarf2/read.c (dw2_symtab_iter_next, dw2_expand_marked_cus): Limit
            PR gold/15646 workaround to symbol kind "type".