]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
s390.c (override_options): Don't emit an error when -mstack-size is used without...
authorAndreas Krebbel <krebbel1@de.ibm.com>
Wed, 7 Mar 2007 09:11:12 +0000 (09:11 +0000)
committerAndreas Krebbel <krebbel@gcc.gnu.org>
Wed, 7 Mar 2007 09:11:12 +0000 (09:11 +0000)
2007-03-07  Andreas Krebbel  <krebbel1@de.ibm.com>

* 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
gcc/config/s390/s390.c
gcc/doc/invoke.texi

index 47057a74863009029fb6b7ee7c9bb01dcf6205aa..5d702fd9cc63eeea4409ab38edeeadd3329fe908 100644 (file)
@@ -1,3 +1,11 @@
+2007-03-07  Andreas Krebbel  <krebbel1@de.ibm.com>
+
+       * 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  <richard@codesourcery.com>
 
        * config/i386/i386.c (output_set_got): Add a GOT initialization
index ad73869888c3ff50a1c110ebc4356f32af78c4ff..784b846f52132f3464dda39d4745f49bc7a0fd4b 100644 (file)
@@ -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 
index 7e15dbfd0620b3c46ee9fa2a7ce1b469149b81f3..f09b9b16aaff08168898fdebdcbf510abf579723 100644 (file)
@@ -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