[PATCH] i386/cygming: Decrease default preferred stack boundary for 32-bit targets
LIU Hao
lh_mouse@126.com
Tue Apr 29 10:29:41 GMT 2025
在 2025-4-29 13:03, LIU Hao 写道:
> This fixes a long-standing issue that GCC used to assume 16-byte stack alignment on i686-w64-mingw32,
> which is not always the case for callbacks from system libraries.
>
CC Zeb Figura
This patch looks a bit risky. The overall effect of `__attribute__((__force_align_arg_pointer__))` seems
to be that it realigns ESP to the _preferred_ alignment, which is changed by this patch.
If we change it to 4 bytes, then incoming alignment == preferred alignment == 4, then suddenly,
`__attribute__((__force_align_arg_pointer__))` no longer has an effect, which may break code that it to
fix stack alignment for SSE.
Maybe we shouldn't apply this patch. This leaves 8-byte alignment unresolved
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111107#c17). But does it harm in practice? `double` on
x86-32 requires only 4-byte alignment despite performance pitfalls. It might be an issue if an atomic
int64 is stored on the stack and is accessed with CMPXCHG8B.
>
> 9005-i386-cygming-Decrease-default-preferred-stack-bounda.patch
>
> From 1b92f8105dbece1694dd3ab398cfb5e3ce2c15d9 Mon Sep 17 00:00:00 2001
> From: LIU Hao<lh_mouse@126.com>
> Date: Tue, 29 Apr 2025 10:43:06 +0800
> Subject: [PATCH] i386/cygming: Decrease default preferred stack boundary for
> 32-bit targets
>
> This commit decreases the default preferred stack boundary to 4.
>
> In i386-options.cc, there's
>
> ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
>
> which sets the default incoming stack boundary to this value, if it's not
> overridden by other options or attributes.
>
> Previously, GCC preferred 16-byte alignment like other platforms, unless
> `-miamcu` was specified. However, the Microsoft x86 ABI only requires the
> stack be aligned to 4-byte boundaries. Callback functions from MSVC code may
> break this assumption by GCC (see reference below), causing local variables
> to be misaligned.
>
> Reference:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111107#c9
> Signed-off-by: LIU Hao<lh_mouse@126.com>
>
> gcc/ChangeLog:
>
> PR 111107
> * config/i386/cygming.h (PREFERRED_STACK_BOUNDARY_DEFAULT): Override
> definition from i386.h.
> ---
> gcc/config/i386/cygming.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h
> index 3ddcbecb22fd..b8c396d35793 100644
> --- a/gcc/config/i386/cygming.h
> +++ b/gcc/config/i386/cygming.h
> @@ -28,6 +28,10 @@ along with GCC; see the file COPYING3. If not see
> #undef TARGET_SEH
> #define TARGET_SEH (TARGET_64BIT_MS_ABI && flag_unwind_tables)
>
> +#undef PREFERRED_STACK_BOUNDARY_DEFAULT
> +#define PREFERRED_STACK_BOUNDARY_DEFAULT \
> + (TARGET_64BIT ? 128 : MIN_STACK_BOUNDARY)
> +
> /* Win64 with SEH cannot represent DRAP stack frames. Disable its use.
> Force the use of different mechanisms to allocate aligned local data. */
> #undef MAX_STACK_ALIGNMENT
> -- 2.49.0
>
--
Best regards,
LIU Hao
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20250429/a3067145/attachment-0001.sig>
More information about the Gcc-patches
mailing list