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]

Re: ada/8358: Ada accesses freed memory


Andreas,

Here's a patch which I have bootstraped i686-linux-gnu-pc with
all checking enabled.

This patch introduces a new GC root which is used to prevent
the pending eleaborations from being GC collected while they
are being enumerated by build_unit_elab.

Ok for mainline?

Graham

ada/ChangeLog

       * trans.c (gnu_pending_elaboration_lists): New GC root.
       (build_unit_elab): Use..

--------------------------------------------------------------------------
Index: trans.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/trans.c,v
retrieving revision 1.21
diff -c -p -r1.21 trans.c
*** trans.c     23 Oct 2002 07:33:34 -0000      1.21
--- trans.c     25 Oct 2002 18:52:50 -0000
*************** tree gnu_block_stack;
*** 88,93 ****
--- 88,97 ----
     handler.  Not used in the zero-cost case.  */
  static GTY(()) tree gnu_except_ptr_stack;

+ /* List of TREE_LIST nodes containing pending elaborations lists.
+    used to prevent the elaborations being reclaimed by GC.  */
+ static GTY(()) tree gnu_pending_elaboration_lists;
+
  /* Map GNAT tree codes to GCC tree codes for simple expressions.  */
  static enum tree_code gnu_codes[Number_Node_Kinds];

*************** build_unit_elab (gnat_unit, body_p, gnu_
*** 5298,5303 ****
--- 5302,5311 ----
    if (gnu_elab_list == 0)
      return 1;

+   /* Prevent the elaboration list from being reclaimed by the GC.  */
+   gnu_pending_elaboration_lists = chainon (gnu_pending_elaboration_lists,
+                                          gnu_elab_list);
+
    /* Set our file and line number to that of the object and set up the
       elaboration routine.  */
    gnu_decl = create_subprog_decl (create_concat_name (gnat_unit,
*************** build_unit_elab (gnat_unit, body_p, gnu_
*** 5357,5362 ****
--- 5365,5373 ----
    poplevel (kept_level_p (), 1, 0);
    gnu_block_stack = TREE_CHAIN (gnu_block_stack);
    end_subprog_body ();
+
+   /* We are finished with the elaboration list it can now be discarded.  */
+   gnu_pending_elaboration_lists = TREE_CHAIN (gnu_pending_elaboration_lists);

    /* If there were no insns, we don't need an elab routine.  It would
       be nice to not output this one, but there's no good way to do that.  */
------------------------------------------------------------------------------


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