Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Compiler problem related to dwarf debug info?



> Hi, I am trying to duplicate your problem, but unfortunately
> it fails to do that, meaning everything went smoothly without
> any problems. 

Hmm, that's strange.

Of course, the fact that it works on netbsd-3 and doesn't on my netbsd-5
system is an indication that there's something sinister afoot either
with my particular build system or with the host compiler, possibly with
my particular instance of it.  I have to admit that my build system once
failed a "read all the files and checksum them, repeatedly, and compare"
test...  However, the powerpc cross-compiler problem has been reproduced
many, many times, and all the involved compilers have been rebuilt from
scratch many times as well, and this problem afflict only my powerpc
cross-built ports, so I've started leaning towards this being an actual
problem.

Some googling led me to

  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36278

and even though it's filed against 4.2.3, 4.3 and 4.4 (ours is 4.1.3),
it at least touches on the same part of the code and fixes an ICE.

The associated change set is at

  http://gcc.gnu.org/viewcvs?view=rev&revision=138369

and I've wedged it into my gcc via the attached patch, and suddenly my
powerpc cross-compilers no longer bomb out with internal compiler errors
due to segfaults when building object files with debugging turned on.
If I've understood correctly, the "!should_emit_struct_debug()" part of
the original change is an optimization to reduce the size of the debug
info which relies on infrastructure not part of gcc 4.1.3.  So... if
someone else see the same problem I do, they can try the attached patch
for the target compiler.

Regards,

- Håvard
Index: dwarf2out.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/gcc4/gcc/dwarf2out.c,v
retrieving revision 1.1.1.5
diff -u -p -r1.1.1.5 dwarf2out.c
--- dwarf2out.c 2 Feb 2008 22:47:58 -0000       1.1.1.5
+++ dwarf2out.c 27 Dec 2008 17:45:06 -0000
@@ -12827,6 +12827,22 @@ is_redundant_typedef (tree decl)
   return 0;
 }
 
+/* Returns the DIE for a context.  */
+
+static inline dw_die_ref
+get_context_die (tree context)
+{
+  if (context)
+    {
+      /* Find die that represents this context.  */
+      if (TYPE_P (context))
+       return force_type_die (context);
+      else
+       return force_decl_die (context);
+    }
+  return comp_unit_die;
+}
+
 /* Returns the DIE for decl.  A DIE will always be returned.  */
 
 static dw_die_ref
@@ -12838,18 +12854,7 @@ force_decl_die (tree decl)
   decl_die = lookup_decl_die (decl);
   if (!decl_die)
     {
-      dw_die_ref context_die;
-      tree decl_context = DECL_CONTEXT (decl);
-      if (decl_context)
-       {
-         /* Find die that represents this context.  */
-         if (TYPE_P (decl_context))
-           context_die = force_type_die (decl_context);
-         else
-           context_die = force_decl_die (decl_context);
-       }
-      else
-       context_die = comp_unit_die;
+      dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
 
       decl_die = lookup_decl_die (decl);
       if (decl_die)
@@ -12904,16 +12909,7 @@ force_type_die (tree type)
   type_die = lookup_type_die (type);
   if (!type_die)
     {
-      dw_die_ref context_die;
-      if (TYPE_CONTEXT (type))
-       {
-         if (TYPE_P (TYPE_CONTEXT (type)))
-           context_die = force_type_die (TYPE_CONTEXT (type));
-         else
-           context_die = force_decl_die (TYPE_CONTEXT (type));
-       }
-      else
-       context_die = comp_unit_die;
+      dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
 
       type_die = lookup_type_die (type);
       if (type_die)
@@ -13236,12 +13232,7 @@ dwarf2out_imported_module_or_decl (tree 
 
   /* Get the scope die for decl context. Use comp_unit_die for global module
      or decl. If die is not found for non globals, force new die.  */
-  if (!context)
-    scope_die = comp_unit_die;
-  else if (TYPE_P (context))
-    scope_die = force_type_die (context);
-  else
-    scope_die = force_decl_die (context);
+  scope_die = get_context_die (context);
 
   /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE.  */
   if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
@@ -13250,6 +13241,16 @@ dwarf2out_imported_module_or_decl (tree 
        at_import_die = base_type_die (TREE_TYPE (decl));
       else
        at_import_die = force_type_die (TREE_TYPE (decl));
+      /* For namespace N { typedef void T; } using N::T; base_type_die
+        returns NULL, but DW_TAG_imported_declaration requires
+        the DW_AT_import tag.  Force creation of DW_TAG_typedef.  */
+      if (!at_import_die)
+       {
+         gcc_assert (TREE_CODE (decl) == TYPE_DECL);
+         gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
+         at_import_die = lookup_type_die (TREE_TYPE (decl));
+         gcc_assert (at_import_die);
+       }
     }
   else
     {
@@ -13261,16 +13262,8 @@ dwarf2out_imported_module_or_decl (tree 
          if (TREE_CODE (decl) == FIELD_DECL)
            {
              tree type = DECL_CONTEXT (decl);
-             dw_die_ref type_context_die;
-
-             if (TYPE_CONTEXT (type))
-               if (TYPE_P (TYPE_CONTEXT (type)))
-                 type_context_die = force_type_die (TYPE_CONTEXT (type));
-             else
-               type_context_die = force_decl_die (TYPE_CONTEXT (type));
-             else
-               type_context_die = comp_unit_die;
-             gen_type_die_for_member (type, decl, type_context_die);
+             gen_type_die_for_member (type, decl,
+                                      get_context_die (TYPE_CONTEXT (type)));
            }
          at_import_die = force_decl_die (decl);
        }


Home | Main Index | Thread Index | Old Index