From: Jim Wilson Date: Thu, 18 Jun 1998 20:17:26 +0000 (+0000) Subject: Fix stack overflow found by glibc compile with max optimizations. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7c74b010d72a4bb1fb6e2647c75a88b865e137b2;p=gcc.git Fix stack overflow found by glibc compile with max optimizations. * 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. From-SVN: r20563 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3263bc0b1e3..9b7d7e477f6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +Thu Jun 18 20:11:00 1998 Jim Wilson + + * 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 * dwarf2out.c (size_of_string): Do count backslashes. diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c index 2416a83fc1d..a4c63a3ae16 100644 --- a/gcc/haifa-sched.c +++ b/gcc/haifa-sched.c @@ -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); diff --git a/gcc/sched.c b/gcc/sched.c index 2cd9d12911c..5b540285676 100644 --- a/gcc/sched.c +++ b/gcc/sched.c @@ -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);