From 690e7b63cf43e7f66b8d9236c66435971ae94e94 Mon Sep 17 00:00:00 2001 From: Andreas Krebbel Date: Wed, 7 Mar 2007 09:11:12 +0000 Subject: [PATCH] s390.c (override_options): Don't emit an error when -mstack-size is used without providing -mstack-guard. 2007-03-07 Andreas Krebbel * config/s390/s390.c (override_options): Don't emit an error when -mstack-size is used without providing -mstack-guard. (s390_emit_prologue): Choose stack_guard value automatically if not provided via command line. * doc/invoke.texi: Adjust description of -mstack-guard and -mstack-size. From-SVN: r122655 --- gcc/ChangeLog | 8 +++++++ gcc/config/s390/s390.c | 54 ++++++++++++++++++++++++++++++------------ gcc/doc/invoke.texi | 20 +++++++++------- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 47057a74863..5d702fd9cc6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2007-03-07 Andreas Krebbel + + * config/s390/s390.c (override_options): Don't emit an error when + -mstack-size is used without providing -mstack-guard. + (s390_emit_prologue): Choose stack_guard value automatically if not + provided via command line. + * doc/invoke.texi: Adjust description of -mstack-guard and -mstack-size. + 2007-03-07 Richard Sandiford * config/i386/i386.c (output_set_got): Add a GOT initialization diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c index ad73869888c..784b846f521 100644 --- a/gcc/config/s390/s390.c +++ b/gcc/config/s390/s390.c @@ -1437,9 +1437,7 @@ override_options (void) if (s390_stack_size) { - if (!s390_stack_guard) - error ("-mstack-size implies use of -mstack-guard"); - else if (s390_stack_guard >= s390_stack_size) + if (s390_stack_guard >= s390_stack_size) error ("stack size must be greater than the stack guard value"); else if (s390_stack_size > 1 << 16) error ("stack size must not be greater than 64k"); @@ -7245,21 +7243,47 @@ s390_emit_prologue (void) if (s390_stack_size) { - HOST_WIDE_INT stack_check_mask = ((s390_stack_size - 1) - & ~(s390_stack_guard - 1)); - rtx t = gen_rtx_AND (Pmode, stack_pointer_rtx, - GEN_INT (stack_check_mask)); + HOST_WIDE_INT stack_guard; - if (TARGET_64BIT) - gen_cmpdi (t, const0_rtx); + if (s390_stack_guard) + stack_guard = s390_stack_guard; else - gen_cmpsi (t, const0_rtx); + { + /* If no value for stack guard is provided the smallest power of 2 + larger than the current frame size is chosen. */ + stack_guard = 1; + while (stack_guard < cfun_frame_layout.frame_size) + stack_guard <<= 1; + } - emit_insn (gen_conditional_trap (gen_rtx_EQ (CCmode, - gen_rtx_REG (CCmode, - CC_REGNUM), - const0_rtx), - const0_rtx)); + if (cfun_frame_layout.frame_size >= s390_stack_size) + { + warning (0, "frame size of function %qs is " + HOST_WIDE_INT_PRINT_DEC + " bytes exceeding user provided stack limit of " + HOST_WIDE_INT_PRINT_DEC " bytes. " + "An unconditional trap is added.", + current_function_name(), cfun_frame_layout.frame_size, + s390_stack_size); + emit_insn (gen_trap ()); + } + else + { + HOST_WIDE_INT stack_check_mask = ((s390_stack_size - 1) + & ~(stack_guard - 1)); + rtx t = gen_rtx_AND (Pmode, stack_pointer_rtx, + GEN_INT (stack_check_mask)); + if (TARGET_64BIT) + gen_cmpdi (t, const0_rtx); + else + gen_cmpsi (t, const0_rtx); + + emit_insn (gen_conditional_trap (gen_rtx_EQ (CCmode, + gen_rtx_REG (CCmode, + CC_REGNUM), + const0_rtx), + const0_rtx)); + } } if (s390_warn_framesize > 0 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 7e15dbfd062..f09b9b16aaf 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -12789,17 +12789,19 @@ sized arrays. This is generally a bad idea with a limited stack size. @item -mstack-size=@var{stack-size} @opindex mstack-guard @opindex mstack-size -These arguments always have to be used in conjunction. If they are present the s390 -back end emits additional instructions in the function prologue which trigger a trap -if the stack size is @var{stack-guard} bytes above the @var{stack-size} -(remember that the stack on s390 grows downward). These options are intended to -be used to help debugging stack overflow problems. The additionally emitted code -causes only little overhead and hence can also be used in production like systems -without greater performance degradation. The given values have to be exact -powers of 2 and @var{stack-size} has to be greater than @var{stack-guard} without -exceeding 64k. +If these options are provided the s390 back end emits additional instructions in +the function prologue which trigger a trap if the stack size is @var{stack-guard} +bytes above the @var{stack-size} (remember that the stack on s390 grows downward). +If the @var{stack-guard} option is omitted the smallest power of 2 larger than +the frame size of the compiled function is chosen. +These options are intended to be used to help debugging stack overflow problems. +The additionally emitted code causes only little overhead and hence can also be +used in production like systems without greater performance degradation. The given +values have to be exact powers of 2 and @var{stack-size} has to be greater than +@var{stack-guard} without exceeding 64k. In order to be efficient the extra code makes the assumption that the stack starts at an address aligned to the value given by @var{stack-size}. +The @var{stack-guard} option can only be used in conjunction with @var{stack-size}. @end table @node Score Options -- 2.30.2