public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
@ 2012-05-20 14:48 H.J. Lu
  2012-05-25 13:53 ` H.J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: H.J. Lu @ 2012-05-20 14:48 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch allows -mpreferred-stack-boundary=3 on x86-64 when SSE is
disabled.  Since this option changes ABI, I also added a warning for
-mpreferred-stack-boundary=3.  OK for trunk?

Thanks.


H.J.
----
	PR target/53383
	* doc/invoke.texi: Add a warning for -mpreferred-stack-boundary=3.

	* config/i386/i386.c (ix86_option_override_internal): Allow
	-mpreferred-stack-boundary=3 for 64-bit if SSE is disenabled.

	* config/i386/i386.h (MIN_STACK_BOUNDARY): Set to 64 for 64-bit
	if SSE is disenabled.

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index eca542c..338d387 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -3660,7 +3660,7 @@ ix86_option_override_internal (bool main_args_p)
   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
   if (global_options_set.x_ix86_preferred_stack_boundary_arg)
     {
-      int min = (TARGET_64BIT ? 4 : 2);
+      int min = (TARGET_64BIT ? (TARGET_SSE ? 4 : 3) : 2);
       int max = (TARGET_SEH ? 4 : 12);
 
       if (ix86_preferred_stack_boundary_arg < min
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index ddb3645..f7f13d2 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -708,7 +708,7 @@ enum target_cpu_default
 #define MAIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)
 
 /* Minimum stack boundary.  */
-#define MIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)
+#define MIN_STACK_BOUNDARY (TARGET_64BIT ? (TARGET_SSE ? 128 : 64) : 32)
 
 /* Boundary (in *bits*) on which the stack pointer prefers to be
    aligned; the compiler cannot rely on having this alignment.  */
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 4c5c79f..daa1f3a 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -13521,6 +13521,12 @@ Attempt to keep the stack boundary aligned to a 2 raised to @var{num}
 byte boundary.  If @option{-mpreferred-stack-boundary} is not specified,
 the default is 4 (16 bytes or 128 bits).
 
+@strong{Warning:} When generating code for the x86-64 architecture with
+SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
+used to keep the stack boundary aligned to 8 byte boundary.  You must
+build all modules with @option{-mpreferred-stack-boundary=3}, including
+any libraries.  This includes the system libraries and startup modules.
+
 @item -mincoming-stack-boundary=@var{num}
 @opindex mincoming-stack-boundary
 Assume the incoming stack is aligned to a 2 raised to @var{num} byte

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-20 14:48 PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64 H.J. Lu
@ 2012-05-25 13:53 ` H.J. Lu
  2012-05-30 18:13   ` H.J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: H.J. Lu @ 2012-05-25 13:53 UTC (permalink / raw)
  To: Jakub Jelinek, Richard Henderson, H. Peter Anvin; +Cc: gcc-patches

On Sun, May 20, 2012 at 7:47 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Hi,
>
> This patch allows -mpreferred-stack-boundary=3 on x86-64 when SSE is
> disabled.  Since this option changes ABI, I also added a warning for
> -mpreferred-stack-boundary=3.  OK for trunk?
>
> Thanks.
>
>
> H.J.
> ----
>        PR target/53383
>        * doc/invoke.texi: Add a warning for -mpreferred-stack-boundary=3.
>
>        * config/i386/i386.c (ix86_option_override_internal): Allow
>        -mpreferred-stack-boundary=3 for 64-bit if SSE is disenabled.
>
>        * config/i386/i386.h (MIN_STACK_BOUNDARY): Set to 64 for 64-bit
>        if SSE is disenabled.
>
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index eca542c..338d387 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -3660,7 +3660,7 @@ ix86_option_override_internal (bool main_args_p)
>   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
>   if (global_options_set.x_ix86_preferred_stack_boundary_arg)
>     {
> -      int min = (TARGET_64BIT ? 4 : 2);
> +      int min = (TARGET_64BIT ? (TARGET_SSE ? 4 : 3) : 2);
>       int max = (TARGET_SEH ? 4 : 12);
>
>       if (ix86_preferred_stack_boundary_arg < min
> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> index ddb3645..f7f13d2 100644
> --- a/gcc/config/i386/i386.h
> +++ b/gcc/config/i386/i386.h
> @@ -708,7 +708,7 @@ enum target_cpu_default
>  #define MAIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)
>
>  /* Minimum stack boundary.  */
> -#define MIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)
> +#define MIN_STACK_BOUNDARY (TARGET_64BIT ? (TARGET_SSE ? 128 : 64) : 32)
>
>  /* Boundary (in *bits*) on which the stack pointer prefers to be
>    aligned; the compiler cannot rely on having this alignment.  */
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 4c5c79f..daa1f3a 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -13521,6 +13521,12 @@ Attempt to keep the stack boundary aligned to a 2 raised to @var{num}
>  byte boundary.  If @option{-mpreferred-stack-boundary} is not specified,
>  the default is 4 (16 bytes or 128 bits).
>
> +@strong{Warning:} When generating code for the x86-64 architecture with
> +SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
> +used to keep the stack boundary aligned to 8 byte boundary.  You must
> +build all modules with @option{-mpreferred-stack-boundary=3}, including
> +any libraries.  This includes the system libraries and startup modules.
> +
>  @item -mincoming-stack-boundary=@var{num}
>  @opindex mincoming-stack-boundary
>  Assume the incoming stack is aligned to a 2 raised to @var{num} byte

I applied the above patch to GCC 4.7 and the following patch to
Linux kernel 3.4.0.  Kernel boots and runs correctly.  Is the patch
OK for trunk?

Thanks.

-- 
H.J.
---
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 94e91e4..cd4a4f7 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -49,6 +49,9 @@ else
         KBUILD_AFLAGS += -m64
         KBUILD_CFLAGS += -m64

+	# Use -mpreferred-stack-boundary=3 if supported.
+	KBUILD_CFLAGS += $(call cc-option,-mno-sse -mpreferred-stack-boundary=3)
+
         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
         cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
         cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-25 13:53 ` H.J. Lu
@ 2012-05-30 18:13   ` H.J. Lu
  2012-06-22 15:04     ` H.J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: H.J. Lu @ 2012-05-30 18:13 UTC (permalink / raw)
  To: Richard Henderson, H. Peter Anvin, Jan Hubicka; +Cc: gcc-patches

On Fri, May 25, 2012 at 6:53 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sun, May 20, 2012 at 7:47 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>> Hi,
>>
>> This patch allows -mpreferred-stack-boundary=3 on x86-64 when SSE is
>> disabled.  Since this option changes ABI, I also added a warning for
>> -mpreferred-stack-boundary=3.  OK for trunk?
>>
>> Thanks.
>>
>>
>> H.J.
>> ----
>>        PR target/53383
>>        * doc/invoke.texi: Add a warning for -mpreferred-stack-boundary=3.
>>
>>        * config/i386/i386.c (ix86_option_override_internal): Allow
>>        -mpreferred-stack-boundary=3 for 64-bit if SSE is disenabled.
>>
>>        * config/i386/i386.h (MIN_STACK_BOUNDARY): Set to 64 for 64-bit
>>        if SSE is disenabled.
>>
>> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
>> index eca542c..338d387 100644
>> --- a/gcc/config/i386/i386.c
>> +++ b/gcc/config/i386/i386.c
>> @@ -3660,7 +3660,7 @@ ix86_option_override_internal (bool main_args_p)
>>   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
>>   if (global_options_set.x_ix86_preferred_stack_boundary_arg)
>>     {
>> -      int min = (TARGET_64BIT ? 4 : 2);
>> +      int min = (TARGET_64BIT ? (TARGET_SSE ? 4 : 3) : 2);
>>       int max = (TARGET_SEH ? 4 : 12);
>>
>>       if (ix86_preferred_stack_boundary_arg < min
>> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
>> index ddb3645..f7f13d2 100644
>> --- a/gcc/config/i386/i386.h
>> +++ b/gcc/config/i386/i386.h
>> @@ -708,7 +708,7 @@ enum target_cpu_default
>>  #define MAIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)
>>
>>  /* Minimum stack boundary.  */
>> -#define MIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)
>> +#define MIN_STACK_BOUNDARY (TARGET_64BIT ? (TARGET_SSE ? 128 : 64) : 32)
>>
>>  /* Boundary (in *bits*) on which the stack pointer prefers to be
>>    aligned; the compiler cannot rely on having this alignment.  */
>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>> index 4c5c79f..daa1f3a 100644
>> --- a/gcc/doc/invoke.texi
>> +++ b/gcc/doc/invoke.texi
>> @@ -13521,6 +13521,12 @@ Attempt to keep the stack boundary aligned to a 2 raised to @var{num}
>>  byte boundary.  If @option{-mpreferred-stack-boundary} is not specified,
>>  the default is 4 (16 bytes or 128 bits).
>>
>> +@strong{Warning:} When generating code for the x86-64 architecture with
>> +SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
>> +used to keep the stack boundary aligned to 8 byte boundary.  You must
>> +build all modules with @option{-mpreferred-stack-boundary=3}, including
>> +any libraries.  This includes the system libraries and startup modules.
>> +
>>  @item -mincoming-stack-boundary=@var{num}
>>  @opindex mincoming-stack-boundary
>>  Assume the incoming stack is aligned to a 2 raised to @var{num} byte
>
> I applied the above patch to GCC 4.7 and the following patch to
> Linux kernel 3.4.0.  Kernel boots and runs correctly.  Is the patch
> OK for trunk?
>
> Thanks.
>
> --
> H.J.
> ---
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index 94e91e4..cd4a4f7 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -49,6 +49,9 @@ else
>         KBUILD_AFLAGS += -m64
>         KBUILD_CFLAGS += -m64
>
> +       # Use -mpreferred-stack-boundary=3 if supported.
> +       KBUILD_CFLAGS += $(call cc-option,-mno-sse -mpreferred-stack-boundary=3)
> +
>         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
>         cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
>         cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)

Ping

-- 
H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-05-30 18:13   ` H.J. Lu
@ 2012-06-22 15:04     ` H.J. Lu
  2012-06-22 17:15       ` Richard Henderson
  2012-06-22 17:16       ` Jan Hubicka
  0 siblings, 2 replies; 11+ messages in thread
From: H.J. Lu @ 2012-06-22 15:04 UTC (permalink / raw)
  To: Richard Henderson, H. Peter Anvin, Jan Hubicka; +Cc: gcc-patches

On Wed, May 30, 2012 at 11:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, May 25, 2012 at 6:53 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Sun, May 20, 2012 at 7:47 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>> Hi,
>>>
>>> This patch allows -mpreferred-stack-boundary=3 on x86-64 when SSE is
>>> disabled.  Since this option changes ABI, I also added a warning for
>>> -mpreferred-stack-boundary=3.  OK for trunk?
>>>
>>> Thanks.
>>>
>>>
>>> H.J.
>>> ----
>>>        PR target/53383
>>>        * doc/invoke.texi: Add a warning for -mpreferred-stack-boundary=3.
>>>
>>>        * config/i386/i386.c (ix86_option_override_internal): Allow
>>>        -mpreferred-stack-boundary=3 for 64-bit if SSE is disenabled.
>>>
>>>        * config/i386/i386.h (MIN_STACK_BOUNDARY): Set to 64 for 64-bit
>>>        if SSE is disenabled.
>>>
>>> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
>>> index eca542c..338d387 100644
>>> --- a/gcc/config/i386/i386.c
>>> +++ b/gcc/config/i386/i386.c
>>> @@ -3660,7 +3660,7 @@ ix86_option_override_internal (bool main_args_p)
>>>   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
>>>   if (global_options_set.x_ix86_preferred_stack_boundary_arg)
>>>     {
>>> -      int min = (TARGET_64BIT ? 4 : 2);
>>> +      int min = (TARGET_64BIT ? (TARGET_SSE ? 4 : 3) : 2);
>>>       int max = (TARGET_SEH ? 4 : 12);
>>>
>>>       if (ix86_preferred_stack_boundary_arg < min
>>> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
>>> index ddb3645..f7f13d2 100644
>>> --- a/gcc/config/i386/i386.h
>>> +++ b/gcc/config/i386/i386.h
>>> @@ -708,7 +708,7 @@ enum target_cpu_default
>>>  #define MAIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)
>>>
>>>  /* Minimum stack boundary.  */
>>> -#define MIN_STACK_BOUNDARY (TARGET_64BIT ? 128 : 32)
>>> +#define MIN_STACK_BOUNDARY (TARGET_64BIT ? (TARGET_SSE ? 128 : 64) : 32)
>>>
>>>  /* Boundary (in *bits*) on which the stack pointer prefers to be
>>>    aligned; the compiler cannot rely on having this alignment.  */
>>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>>> index 4c5c79f..daa1f3a 100644
>>> --- a/gcc/doc/invoke.texi
>>> +++ b/gcc/doc/invoke.texi
>>> @@ -13521,6 +13521,12 @@ Attempt to keep the stack boundary aligned to a 2 raised to @var{num}
>>>  byte boundary.  If @option{-mpreferred-stack-boundary} is not specified,
>>>  the default is 4 (16 bytes or 128 bits).
>>>
>>> +@strong{Warning:} When generating code for the x86-64 architecture with
>>> +SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
>>> +used to keep the stack boundary aligned to 8 byte boundary.  You must
>>> +build all modules with @option{-mpreferred-stack-boundary=3}, including
>>> +any libraries.  This includes the system libraries and startup modules.
>>> +
>>>  @item -mincoming-stack-boundary=@var{num}
>>>  @opindex mincoming-stack-boundary
>>>  Assume the incoming stack is aligned to a 2 raised to @var{num} byte
>>
>> I applied the above patch to GCC 4.7 and the following patch to
>> Linux kernel 3.4.0.  Kernel boots and runs correctly.  Is the patch
>> OK for trunk?
>>
>> Thanks.
>>
>> --
>> H.J.
>> ---
>> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
>> index 94e91e4..cd4a4f7 100644
>> --- a/arch/x86/Makefile
>> +++ b/arch/x86/Makefile
>> @@ -49,6 +49,9 @@ else
>>         KBUILD_AFLAGS += -m64
>>         KBUILD_CFLAGS += -m64
>>
>> +       # Use -mpreferred-stack-boundary=3 if supported.
>> +       KBUILD_CFLAGS += $(call cc-option,-mno-sse -mpreferred-stack-boundary=3)
>> +
>>         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
>>         cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
>>         cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
>
> Ping
>

Ping.

I have been running Linux kernel compiled with this option for
weeks.  Since -mpreferred-stack-boundary=3 will only be allowed
with -mno-sse, it will be used only with incompatible ABI.  Any
objections to this patch?

Thanks.


-- 
H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-06-22 15:04     ` H.J. Lu
@ 2012-06-22 17:15       ` Richard Henderson
  2012-06-22 17:16       ` Jan Hubicka
  1 sibling, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2012-06-22 17:15 UTC (permalink / raw)
  To: H.J. Lu; +Cc: H. Peter Anvin, Jan Hubicka, gcc-patches

On 06/22/2012 06:46 AM, H.J. Lu wrote:
> Ping.
> 
> I have been running Linux kernel compiled with this option for
> weeks.  Since -mpreferred-stack-boundary=3 will only be allowed
> with -mno-sse, it will be used only with incompatible ABI.  Any
> objections to this patch?
> 
> Thanks.

The patch is ok.


r~

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-06-22 15:04     ` H.J. Lu
  2012-06-22 17:15       ` Richard Henderson
@ 2012-06-22 17:16       ` Jan Hubicka
  2012-06-22 18:16         ` H.J. Lu
  1 sibling, 1 reply; 11+ messages in thread
From: Jan Hubicka @ 2012-06-22 17:16 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Richard Henderson, H. Peter Anvin, Jan Hubicka, gcc-patches

> >>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> >>> index 4c5c79f..daa1f3a 100644
> >>> --- a/gcc/doc/invoke.texi
> >>> +++ b/gcc/doc/invoke.texi
> >>> @@ -13521,6 +13521,12 @@ Attempt to keep the stack boundary aligned to a 2 raised to @var{num}
> >>>  byte boundary.  If @option{-mpreferred-stack-boundary} is not specified,
> >>>  the default is 4 (16 bytes or 128 bits).
> >>>
> >>> +@strong{Warning:} When generating code for the x86-64 architecture with
> >>> +SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
> >>> +used to keep the stack boundary aligned to 8 byte boundary.  You must
> >>> +build all modules with @option{-mpreferred-stack-boundary=3}, including
> >>> +any libraries.  This includes the system libraries and startup modules.

I would suggest to re-word this paragraph.
Perhaps something along lines

x86-64 ABI require 16 byte stack alignment. It is possible to compile code with
-mpreferred-stack-boundary=3 where stack alignment is 8 bytes only.  This is
ABI incompatible and intended to be used in controlled environment where stack
space is important limitation. It may lead to wrong code when functions
compiled with 16 byte stack alignment (such as functions from a standard
library) are called with misaligned stack.  In this case the of SSE registers
may lead to misaligned memory access traps. In addition, va-arg will
incorrectly handle 16 byte aligned objects (including x87 long double and
__int128) leading to wrong results rather than traps.

Fell free to fix my english and extend it.  I just want to make it sure
that the paragraph explains how things break (i.e. by calling something
with default stack alignment from function with 8byte alignment.) and that
it can break for non-SSE code, too, when using va-args on 16 byte aligned
objects.

The patch is fine with this change.  Please also add change to news.html with
similar explanation.

Honza
> >>> +
> >>>  @item -mincoming-stack-boundary=@var{num}
> >>>  @opindex mincoming-stack-boundary
> >>>  Assume the incoming stack is aligned to a 2 raised to @var{num} byte
> >>
> >> I applied the above patch to GCC 4.7 and the following patch to
> >> Linux kernel 3.4.0.  Kernel boots and runs correctly.  Is the patch
> >> OK for trunk?
> >>
> >> Thanks.
> >>
> >> --
> >> H.J.
> >> ---
> >> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> >> index 94e91e4..cd4a4f7 100644
> >> --- a/arch/x86/Makefile
> >> +++ b/arch/x86/Makefile
> >> @@ -49,6 +49,9 @@ else
> >>         KBUILD_AFLAGS += -m64
> >>         KBUILD_CFLAGS += -m64
> >>
> >> +       # Use -mpreferred-stack-boundary=3 if supported.
> >> +       KBUILD_CFLAGS += $(call cc-option,-mno-sse -mpreferred-stack-boundary=3)
> >> +
> >>         # FIXME - should be integrated in Makefile.cpu (Makefile_32.cpu)
> >>         cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8)
> >>         cflags-$(CONFIG_MPSC) += $(call cc-option,-march=nocona)
> >
> > Ping
> >
> 
> Ping.
> 
> I have been running Linux kernel compiled with this option for
> weeks.  Since -mpreferred-stack-boundary=3 will only be allowed
> with -mno-sse, it will be used only with incompatible ABI.  Any
> objections to this patch?
> 
> Thanks.
> 
> 
> -- 
> H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-06-22 17:16       ` Jan Hubicka
@ 2012-06-22 18:16         ` H.J. Lu
  2012-06-22 18:19           ` Jan Hubicka
  0 siblings, 1 reply; 11+ messages in thread
From: H.J. Lu @ 2012-06-22 18:16 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: Richard Henderson, H. Peter Anvin, gcc-patches

On Fri, Jun 22, 2012 at 10:11 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
>> >>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>> >>> index 4c5c79f..daa1f3a 100644
>> >>> --- a/gcc/doc/invoke.texi
>> >>> +++ b/gcc/doc/invoke.texi
>> >>> @@ -13521,6 +13521,12 @@ Attempt to keep the stack boundary aligned to a 2 raised to @var{num}
>> >>>  byte boundary.  If @option{-mpreferred-stack-boundary} is not specified,
>> >>>  the default is 4 (16 bytes or 128 bits).
>> >>>
>> >>> +@strong{Warning:} When generating code for the x86-64 architecture with
>> >>> +SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
>> >>> +used to keep the stack boundary aligned to 8 byte boundary.  You must
>> >>> +build all modules with @option{-mpreferred-stack-boundary=3}, including
>> >>> +any libraries.  This includes the system libraries and startup modules.
>
> I would suggest to re-word this paragraph.
> Perhaps something along lines
>
> x86-64 ABI require 16 byte stack alignment. It is possible to compile code with
> -mpreferred-stack-boundary=3 where stack alignment is 8 bytes only.  This is
> ABI incompatible and intended to be used in controlled environment where stack
> space is important limitation. It may lead to wrong code when functions
> compiled with 16 byte stack alignment (such as functions from a standard
> library) are called with misaligned stack.  In this case the of SSE registers
> may lead to misaligned memory access traps. In addition, va-arg will
> incorrectly handle 16 byte aligned objects (including x87 long double and
> __int128) leading to wrong results rather than traps.
>
> Fell free to fix my english and extend it.  I just want to make it sure
> that the paragraph explains how things break (i.e. by calling something
> with default stack alignment from function with 8byte alignment.) and that
> it can break for non-SSE code, too, when using va-args on 16 byte aligned
> objects.
>
> The patch is fine with this change.  Please also add change to news.html with
> similar explanation.
>

Here is the patch for invoke.texi.  OK to install?

I will prepare a similar one for news.html.

Thanks.

-- 
H.J.
---
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 029a7ab..87e0d1c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -13579,9 +13579,18 @@ the default is 4 (16 bytes or 128 bits).

 @strong{Warning:} When generating code for the x86-64 architecture with
 SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
-used to keep the stack boundary aligned to 8 byte boundary.  You must
-build all modules with @option{-mpreferred-stack-boundary=3}, including
-any libraries.  This includes the system libraries and startup modules.
+used to keep the stack boundary aligned to 8 byte boundary.  Since
+x86-64 ABI require 16 byte stack alignment, this is ABI incompatible and
+intended to be used in controlled environment where stack space is
+important limitation.  This option will lead to wrong code when functions
+compiled with 16 byte stack alignment (such as functions from a standard
+library) are called with misaligned stack.  In this case, SSE
+instructions may lead to misaligned memory access traps.  In addition,
+variable arguments will be handled incorrectly for 16 byte aligned
+objects (including x87 long double and __int128), leading to wrong
+results.  You must build all modules with
+@option{-mpreferred-stack-boundary=3}, including any libraries.  This
+includes the system libraries and startup modules.

 @item -mincoming-stack-boundary=@var{num}
 @opindex mincoming-stack-boundary

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-06-22 18:16         ` H.J. Lu
@ 2012-06-22 18:19           ` Jan Hubicka
  2012-06-22 19:08             ` H.J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: Jan Hubicka @ 2012-06-22 18:19 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jan Hubicka, Richard Henderson, H. Peter Anvin, gcc-patches

> >
> 
> Here is the patch for invoke.texi.  OK to install?
> 
> I will prepare a similar one for news.html.
> 
> Thanks.
> 
> -- 
> H.J.
> ---
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 029a7ab..87e0d1c 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -13579,9 +13579,18 @@ the default is 4 (16 bytes or 128 bits).
> 
>  @strong{Warning:} When generating code for the x86-64 architecture with
>  SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
> -used to keep the stack boundary aligned to 8 byte boundary.  You must
> -build all modules with @option{-mpreferred-stack-boundary=3}, including
> -any libraries.  This includes the system libraries and startup modules.
> +used to keep the stack boundary aligned to 8 byte boundary.  Since
> +x86-64 ABI require 16 byte stack alignment, this is ABI incompatible and
> +intended to be used in controlled environment where stack space is
> +important limitation.  This option will lead to wrong code when functions
> +compiled with 16 byte stack alignment (such as functions from a standard
> +library) are called with misaligned stack.  In this case, SSE
> +instructions may lead to misaligned memory access traps.  In addition,
> +variable arguments will be handled incorrectly for 16 byte aligned
> +objects (including x87 long double and __int128), leading to wrong
> +results.  You must build all modules with
> +@option{-mpreferred-stack-boundary=3}, including any libraries.  This
> +includes the system libraries and startup modules.

This is not true in a strict sense. One can build some part with 16 byte
alignment and just watch to not call from 8byte world to 16byte world, but I am
fine with it. (I guess -mpreferred-stack-boundary=3 is something to try on
recursion heavy benchmarks as some in SPEC and I would also expect resulting
binary to just work most of time ;)

OK, Thanks!
Honza
> 
>  @item -mincoming-stack-boundary=@var{num}
>  @opindex mincoming-stack-boundary

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-06-22 18:19           ` Jan Hubicka
@ 2012-06-22 19:08             ` H.J. Lu
  2012-06-22 19:27               ` Jan Hubicka
  2012-07-15 21:49               ` Gerald Pfeifer
  0 siblings, 2 replies; 11+ messages in thread
From: H.J. Lu @ 2012-06-22 19:08 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: Richard Henderson, H. Peter Anvin, gcc-patches

On Fri, Jun 22, 2012 at 11:15 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
>> >
>>
>> Here is the patch for invoke.texi.  OK to install?
>>
>> I will prepare a similar one for news.html.
>>
>> Thanks.
>>
>> --
>> H.J.
>> ---
>> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
>> index 029a7ab..87e0d1c 100644
>> --- a/gcc/doc/invoke.texi
>> +++ b/gcc/doc/invoke.texi
>> @@ -13579,9 +13579,18 @@ the default is 4 (16 bytes or 128 bits).
>>
>>  @strong{Warning:} When generating code for the x86-64 architecture with
>>  SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
>> -used to keep the stack boundary aligned to 8 byte boundary.  You must
>> -build all modules with @option{-mpreferred-stack-boundary=3}, including
>> -any libraries.  This includes the system libraries and startup modules.
>> +used to keep the stack boundary aligned to 8 byte boundary.  Since
>> +x86-64 ABI require 16 byte stack alignment, this is ABI incompatible and
>> +intended to be used in controlled environment where stack space is
>> +important limitation.  This option will lead to wrong code when functions
>> +compiled with 16 byte stack alignment (such as functions from a standard
>> +library) are called with misaligned stack.  In this case, SSE
>> +instructions may lead to misaligned memory access traps.  In addition,
>> +variable arguments will be handled incorrectly for 16 byte aligned
>> +objects (including x87 long double and __int128), leading to wrong
>> +results.  You must build all modules with
>> +@option{-mpreferred-stack-boundary=3}, including any libraries.  This
>> +includes the system libraries and startup modules.
>
> This is not true in a strict sense. One can build some part with 16 byte
> alignment and just watch to not call from 8byte world to 16byte world, but I am
> fine with it. (I guess -mpreferred-stack-boundary=3 is something to try on
> recursion heavy benchmarks as some in SPEC and I would also expect resulting
> binary to just work most of time ;)
>
> OK, Thanks!
> Honza
>>
>>  @item -mincoming-stack-boundary=@var{num}
>>  @opindex mincoming-stack-boundary

I am not sure if news.html is the best place for this.
How about putting it in gcc-4.8/changes.html? Does
it look OK?

Thanks.

-- 
H.J.
---
Index: ./gcc-4.8/changes.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-4.8/changes.html,v
retrieving revision 1.2
diff -u -p -r1.2 changes.html
--- ./gcc-4.8/changes.html	28 Apr 2012 01:58:33 -0000	1.2
+++ ./gcc-4.8/changes.html	22 Jun 2012 18:23:01 -0000
@@ -61,9 +61,24 @@

 <!--
 <h2 id="targets">New Targets and Target Specific Improvements</h2>
-
 -->

+<h3>IA-32/x86-64</h3>
+  <ul>
+    <li>Allow <code>-mpreferred-stack-boundary=3</code> for the x86-64
+    architecture with SSE extensions disabled.  Since x86-64 ABI require
+    16 byte stack alignment, this is ABI incompatible and intended to be
+    used in controlled environment where stack space is important limitation.
+    This option will lead to wrong code when functions compiled with 16 byte
+    stack alignment (such as functions from a standard library) are called
+    with misaligned stack.  In this case, SSE instructions may lead to
+    misaligned memory access traps.  In addition, variable arguments will
+    be handled incorrectly for 16 byte aligned objects (including x87
+    long double and __int128), leading to wrong results.  You must build all
+    modules with <code>-mpreferred-stack-boundary=3</code>, including any
+    libraries.  This includes the system libraries and startup modules.</li>
+  </ul>
+
 <!--
 <h2>Documentation improvements</h2>
 -->

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-06-22 19:08             ` H.J. Lu
@ 2012-06-22 19:27               ` Jan Hubicka
  2012-07-15 21:49               ` Gerald Pfeifer
  1 sibling, 0 replies; 11+ messages in thread
From: Jan Hubicka @ 2012-06-22 19:27 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jan Hubicka, Richard Henderson, H. Peter Anvin, gcc-patches

> On Fri, Jun 22, 2012 at 11:15 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
> >> >
> >>
> >> Here is the patch for invoke.texi.  OK to install?
> >>
> >> I will prepare a similar one for news.html.
> >>
> >> Thanks.
> >>
> >> --
> >> H.J.
> >> ---
> >> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> >> index 029a7ab..87e0d1c 100644
> >> --- a/gcc/doc/invoke.texi
> >> +++ b/gcc/doc/invoke.texi
> >> @@ -13579,9 +13579,18 @@ the default is 4 (16 bytes or 128 bits).
> >>
> >>  @strong{Warning:} When generating code for the x86-64 architecture with
> >>  SSE extensions disabled, @option{-mpreferred-stack-boundary=3} can be
> >> -used to keep the stack boundary aligned to 8 byte boundary.  You must
> >> -build all modules with @option{-mpreferred-stack-boundary=3}, including
> >> -any libraries.  This includes the system libraries and startup modules.
> >> +used to keep the stack boundary aligned to 8 byte boundary.  Since
> >> +x86-64 ABI require 16 byte stack alignment, this is ABI incompatible and
> >> +intended to be used in controlled environment where stack space is
> >> +important limitation.  This option will lead to wrong code when functions
> >> +compiled with 16 byte stack alignment (such as functions from a standard
> >> +library) are called with misaligned stack.  In this case, SSE
> >> +instructions may lead to misaligned memory access traps.  In addition,
> >> +variable arguments will be handled incorrectly for 16 byte aligned
> >> +objects (including x87 long double and __int128), leading to wrong
> >> +results.  You must build all modules with
> >> +@option{-mpreferred-stack-boundary=3}, including any libraries.  This
> >> +includes the system libraries and startup modules.
> >
> > This is not true in a strict sense. One can build some part with 16 byte
> > alignment and just watch to not call from 8byte world to 16byte world, but I am
> > fine with it. (I guess -mpreferred-stack-boundary=3 is something to try on
> > recursion heavy benchmarks as some in SPEC and I would also expect resulting
> > binary to just work most of time ;)
> >
> > OK, Thanks!
> > Honza
> >>
> >>  @item -mincoming-stack-boundary=@var{num}
> >>  @opindex mincoming-stack-boundary
> 
> I am not sure if news.html is the best place for this.
> How about putting it in gcc-4.8/changes.html? Does
> it look OK?

Yes, I meant changes.html, sorry.
Just to have it documented since when this is allowed.

Thanks,
Honza

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64
  2012-06-22 19:08             ` H.J. Lu
  2012-06-22 19:27               ` Jan Hubicka
@ 2012-07-15 21:49               ` Gerald Pfeifer
  1 sibling, 0 replies; 11+ messages in thread
From: Gerald Pfeifer @ 2012-07-15 21:49 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jan Hubicka, Richard Henderson, H. Peter Anvin, gcc-patches

On Fri, 22 Jun 2012, H.J. Lu wrote:
> I am not sure if news.html is the best place for this.

news.html definitely is not a good place for this, cf. the comment
  <!-- ATTENTION: This page is for *OLD* news!  Latest news goes first. -->
in that file. ;-)

> How about putting it in gcc-4.8/changes.html?

Yes, that fits.

> Does it look OK?

Index: ./gcc-4.8/changes.html
===================================================================
+    <li>Allow <code>-mpreferred-stack-boundary=3</code> for the x86-64
+    architecture with SSE extensions disabled.  Since x86-64 ABI require

the...ABI
requires

+    used in controlled environment where stack space is important limitation.

is an important limitation

+    long double and __int128), leading to wrong results.  You must build all

<code>...</code>

And the header for the supersection was missing.  

All fixed with the patch below which I committed.


Index: gcc-4.8/changes.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-4.8/changes.html,v
retrieving revision 1.4
diff -u -3 -p -r1.4 changes.html
--- gcc-4.8/changes.html	2 Jul 2012 11:35:28 -0000	1.4
+++ gcc-4.8/changes.html	15 Jul 2012 21:23:19 -0000
@@ -63,22 +63,22 @@ more information about requirements to b
 <h3>Java (GCJ)</h3>
 -->
 
-<!--
 <h2 id="targets">New Targets and Target Specific Improvements</h2>
--->
 
 <h3>IA-32/x86-64</h3>
   <ul>
     <li>Allow <code>-mpreferred-stack-boundary=3</code> for the x86-64
-    architecture with SSE extensions disabled.  Since x86-64 ABI require
-    16 byte stack alignment, this is ABI incompatible and intended to be
-    used in controlled environment where stack space is important limitation.
+    architecture with SSE extensions disabled.  Since the x86-64 ABI
+    requires 16 byte stack alignment, this is ABI incompatible and
+    intended to be used in controlled environments where stack space
+    is an important limitation.
     This option will lead to wrong code when functions compiled with 16 byte
     stack alignment (such as functions from a standard library) are called
     with misaligned stack.  In this case, SSE instructions may lead to
     misaligned memory access traps.  In addition, variable arguments will
     be handled incorrectly for 16 byte aligned objects (including x87
-    long double and __int128), leading to wrong results.  You must build all
+    <code>long double</code> and <code>__int128</code>), leading to
+    wrong results.  You must build all
     modules with <code>-mpreferred-stack-boundary=3</code>, including any
     libraries.  This includes the system libraries and startup modules.</li>
   </ul>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-07-15 21:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-20 14:48 PATCH: PR target/53383: Allow -mpreferred-stack-boundary=3 on x86-64 H.J. Lu
2012-05-25 13:53 ` H.J. Lu
2012-05-30 18:13   ` H.J. Lu
2012-06-22 15:04     ` H.J. Lu
2012-06-22 17:15       ` Richard Henderson
2012-06-22 17:16       ` Jan Hubicka
2012-06-22 18:16         ` H.J. Lu
2012-06-22 18:19           ` Jan Hubicka
2012-06-22 19:08             ` H.J. Lu
2012-06-22 19:27               ` Jan Hubicka
2012-07-15 21:49               ` Gerald Pfeifer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).