]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix use of "main" marker in gdb index
authorTom Tromey <tom@tromey.com>
Mon, 22 Sep 2025 15:08:46 +0000 (09:08 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 14 Oct 2025 16:18:09 +0000 (10:18 -0600)
Tom de Vries noticed that with .gdb_index, the "main" marker would
sometimes seemingly be ignored.

I tracked this down to an interaction between the rewritten reader and
the "main"-finding code in cooked_index.  With the ordinary DWARF
scanner, a C "main" won't be marked as IS_MAIN; whereas with
.gdb_index this can happen.  In this case, the code thinks that C
requires canonicalization (which is only true for types), and skips
using the symbol.

This patch fixes the problem and adds some comments explaining what is
going on.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33441

gdb/dwarf2/cooked-index-shard.c
gdb/dwarf2/cooked-index.c

index e440d85e1c9fa263e24021d794b6b57e675e28ed..58a02316e63ba481ea4af736a7fd9bc28b00330d 100644 (file)
@@ -224,7 +224,8 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps)
        }
 
       /* Note that this code must be kept in sync with
-        language_requires_canonicalization.  */
+        cooked_index::get_main -- if canonicalization is required
+        here, then a check might be required there.  */
       gdb_assert (entry->canonical == nullptr);
       if ((entry->flags & IS_LINKAGE) != 0)
        entry->canonical = entry->name;
index 6209590febb784d7761f157c45ebeb2ec911c47f..fbcfe8ff3b664058a7b7c9babbe1afaf7a27a7eb 100644 (file)
    here, and then these are all waited for before exit proceeds.  */
 static gdb::unordered_set<cooked_index *> active_vectors;
 
-/* Return true if LANG requires canonicalization.  This is used
-   primarily to work around an issue computing the name of "main".
-   This function must be kept in sync with
-   cooked_index_shard::finalize.  */
-
-static bool
-language_requires_canonicalization (enum language lang)
-{
-  return (lang == language_ada
-         || lang == language_c
-         || lang == language_cplus);
-}
-
 cooked_index::cooked_index (cooked_index_worker_up &&worker)
   : m_state (std::move (worker))
 {
@@ -201,7 +188,11 @@ cooked_index::get_main () const
        {
          if ((entry->flags & IS_MAIN) != 0)
            {
-             if (!language_requires_canonicalization (entry->lang))
+             /* This should be kept in sync with
+                cooked_index_shard::finalize.  Note that there, C
+                requires canonicalization -- but that is only for
+                types, 'main' doesn't count.  */
+             if (entry->lang != language_ada && entry->lang != language_cplus)
                {
                  /* There won't be one better than this.  */
                  return entry;