This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[dwarf4 patch] Fix memory corruption problem when using -gdwarf-4


I'm checking in this patch to the dwarf4 branch to fix a memory
corruption problem in copy_decls_walk(), caused by keeping a hash
table slot pointer live across a mutually-recursive call that could
result in hash table expansion. If the table is expanded, the slot
pointer is no longer valid, so I needed to move the code that used the
pointer above the recursive call.

-cary


	* dwarf2out.c (copy_decls_walk): Move use of hash table slot pointer
	to fix memory corruption problem.


Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 148092)
+++ dwarf2out.c	(working copy)
@@ -8690,6 +8690,15 @@ copy_decls_walk (dw_die_ref unit, dw_die
               dw_die_ref parent = unit;
               dw_die_ref copy = clone_tree (targ);

+              /* Record in DECL_TABLE that TARG has been copied.
+                 Need to do this now, before the recursive call,
+                 because DECL_TABLE may be expanded and SLOT
+                 would no longer be a valid pointer.  */
+              entry = XCNEW (struct decl_table_entry);
+              entry->orig = targ;
+              entry->copy = copy;
+              *slot = entry;
+
               /* If TARG has surrounding context, copy its ancestor tree
                  into the new type unit.  */
               if (targ->die_parent != NULL
@@ -8700,12 +8709,6 @@ copy_decls_walk (dw_die_ref unit, dw_die

               add_child_die (parent, copy);
               a->dw_attr_val.v.val_die_ref.die = copy;
-
-              /* Record in DECL_TABLE that TARG has been copied.  */
-              entry = XCNEW (struct decl_table_entry);
-              entry->orig = targ;
-              entry->copy = copy;
-              *slot = entry;
             }
         }
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]