OSDN Git Service

Fix stack overflow found by glibc compile with max optimizations.
authorwilson <wilson@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Jun 1998 20:17:26 +0000 (20:17 +0000)
committerwilson <wilson@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Jun 1998 20:17:26 +0000 (20:17 +0000)
* sched.c (schedule_insns): Use xmalloc not alloca for max_uid
indexed arrays.  Call free at the end of the function for them.
* haifa-sched.c (schedule_insns): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@20563 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/haifa-sched.c
gcc/sched.c

index 3263bc0..9b7d7e4 100644 (file)
@@ -1,3 +1,9 @@
+Thu Jun 18 20:11:00 1998  Jim Wilson  <wilson@cygnus.com>
+
+       * sched.c (schedule_insns): Use xmalloc not alloca for max_uid
+       indexed arrays.  Call free at the end of the function for them.
+       * haifa-sched.c (schedule_insns): Likewise.
+
 Thu Jun 18 18:16:01 1998  Jim Wilson  <wilson@cygnus.com>
 
        * dwarf2out.c (size_of_string): Do count backslashes.
index 2416a83..a4c63a3 100644 (file)
@@ -8447,17 +8447,17 @@ schedule_insns (dump_file)
 
   max_uid = (get_max_uid () + 1);
 
-  cant_move = (char *) alloca (max_uid * sizeof (char));
+  cant_move = (char *) xmalloc (max_uid * sizeof (char));
   bzero ((char *) cant_move, max_uid * sizeof (char));
 
-  fed_by_spec_load = (char *) alloca (max_uid * sizeof (char));
+  fed_by_spec_load = (char *) xmalloc (max_uid * sizeof (char));
   bzero ((char *) fed_by_spec_load, max_uid * sizeof (char));
 
-  is_load_insn = (char *) alloca (max_uid * sizeof (char));
+  is_load_insn = (char *) xmalloc (max_uid * sizeof (char));
   bzero ((char *) is_load_insn, max_uid * sizeof (char));
 
-  insn_orig_block = (int *) alloca (max_uid * sizeof (int));
-  insn_luid = (int *) alloca (max_uid * sizeof (int));
+  insn_orig_block = (int *) xmalloc (max_uid * sizeof (int));
+  insn_luid = (int *) xmalloc (max_uid * sizeof (int));
 
   luid = 0;
   for (b = 0; b < n_basic_blocks; b++)
@@ -8577,18 +8577,22 @@ schedule_insns (dump_file)
     }
 
   /* Allocate data for this pass.  See comments, above,
-     for what these vectors do.  */
-  insn_priority = (int *) alloca (max_uid * sizeof (int));
-  insn_reg_weight = (int *) alloca (max_uid * sizeof (int));
-  insn_tick = (int *) alloca (max_uid * sizeof (int));
-  insn_costs = (short *) alloca (max_uid * sizeof (short));
-  insn_units = (short *) alloca (max_uid * sizeof (short));
-  insn_blockage = (unsigned int *) alloca (max_uid * sizeof (unsigned int));
-  insn_ref_count = (int *) alloca (max_uid * sizeof (int));
+     for what these vectors do.
+
+     We use xmalloc instead of alloca, because max_uid can be very large
+     when there is a lot of function inlining.  If we used alloca, we could
+     exceed stack limits on some hosts for some inputs.  */
+  insn_priority = (int *) xmalloc (max_uid * sizeof (int));
+  insn_reg_weight = (int *) xmalloc (max_uid * sizeof (int));
+  insn_tick = (int *) xmalloc (max_uid * sizeof (int));
+  insn_costs = (short *) xmalloc (max_uid * sizeof (short));
+  insn_units = (short *) xmalloc (max_uid * sizeof (short));
+  insn_blockage = (unsigned int *) xmalloc (max_uid * sizeof (unsigned int));
+  insn_ref_count = (int *) xmalloc (max_uid * sizeof (int));
 
   /* Allocate for forward dependencies */
-  insn_dep_count = (int *) alloca (max_uid * sizeof (int));
-  insn_depend = (rtx *) alloca (max_uid * sizeof (rtx));
+  insn_dep_count = (int *) xmalloc (max_uid * sizeof (int));
+  insn_depend = (rtx *) xmalloc (max_uid * sizeof (rtx));
 
   if (reload_completed == 0)
     {
@@ -8616,7 +8620,7 @@ schedule_insns (dump_file)
     {
       rtx line;
 
-      line_note = (rtx *) alloca (max_uid * sizeof (rtx));
+      line_note = (rtx *) xmalloc (max_uid * sizeof (rtx));
       bzero ((char *) line_note, max_uid * sizeof (rtx));
       line_note_head = (rtx *) alloca (n_basic_blocks * sizeof (rtx));
       bzero ((char *) line_note_head, n_basic_blocks * sizeof (rtx));
@@ -8703,6 +8707,26 @@ schedule_insns (dump_file)
       fprintf (dump, "\n\n");
     }
 
+  free (cant_move);
+  free (fed_by_spec_load);
+  free (is_load_insn);
+  free (insn_orig_block);
+  free (insn_luid);
+
+  free (insn_priority);
+  free (insn_reg_weight);
+  free (insn_tick);
+  free (insn_costs);
+  free (insn_units);
+  free (insn_blockage);
+  free (insn_ref_count);
+
+  free (insn_dep_count);
+  free (insn_depend);
+
+  if (write_symbols != NO_DEBUG)
+    free (line_note);
+
   if (bb_live_regs)
     FREE_REG_SET (bb_live_regs);
 
index 2cd9d12..5b54028 100644 (file)
@@ -4293,14 +4293,18 @@ schedule_insns (dump_file)
      remember how far we can cut back the stack on exit.  */
 
   /* Allocate data for this pass.  See comments, above,
-     for what these vectors do.  */
-  insn_luid = (int *) alloca (max_uid * sizeof (int));
-  insn_priority = (int *) alloca (max_uid * sizeof (int));
-  insn_tick = (int *) alloca (max_uid * sizeof (int));
-  insn_costs = (short *) alloca (max_uid * sizeof (short));
-  insn_units = (short *) alloca (max_uid * sizeof (short));
-  insn_blockage = (unsigned int *) alloca (max_uid * sizeof (unsigned int));
-  insn_ref_count = (int *) alloca (max_uid * sizeof (int));
+     for what these vectors do.
+
+     We use xmalloc instead of alloca, because max_uid can be very large
+     when there is a lot of function inlining.  If we used alloca, we could
+     exceed stack limits on some hosts for some inputs.  */
+  insn_luid = (int *) xmalloc (max_uid * sizeof (int));
+  insn_priority = (int *) xmalloc (max_uid * sizeof (int));
+  insn_tick = (int *) xmalloc (max_uid * sizeof (int));
+  insn_costs = (short *) xmalloc (max_uid * sizeof (short));
+  insn_units = (short *) xmalloc (max_uid * sizeof (short));
+  insn_blockage = (unsigned int *) xmalloc (max_uid * sizeof (unsigned int));
+  insn_ref_count = (int *) xmalloc (max_uid * sizeof (int));
 
   if (reload_completed == 0)
     {
@@ -4324,7 +4328,7 @@ schedule_insns (dump_file)
     {
       rtx line;
 
-      line_note = (rtx *) alloca (max_uid * sizeof (rtx));
+      line_note = (rtx *) xmalloc (max_uid * sizeof (rtx));
       bzero ((char *) line_note, max_uid * sizeof (rtx));
       line_note_head = (rtx *) alloca (n_basic_blocks * sizeof (rtx));
       bzero ((char *) line_note_head, n_basic_blocks * sizeof (rtx));
@@ -4561,6 +4565,17 @@ schedule_insns (dump_file)
          }
     }
 
+  free (insn_luid);
+  free (insn_priority);
+  free (insn_tick);
+  free (insn_costs);
+  free (insn_units);
+  free (insn_blockage);
+  free (insn_ref_count);
+
+  if (write_symbols != NO_DEBUG)
+    free (line_note);
+
   if (reload_completed == 0)
     {
       FREE_REG_SET (bb_dead_regs);