From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2851B3855592; Tue, 22 Aug 2023 21:27:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2851B3855592 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692739653; bh=wcebr0xZkgg8/nTwuZmvOm26YLo6hU7+phAvri3AqNw=; h=From:To:Subject:Date:From; b=QTZu+yuECSBdUdYN0V56XAOOeC7BVPYHlDL1jNFPQgG1IFb69iaHDkzURDue3cLWR 0/2YeLzX4MozieHdtMB/EotKGvihkEb/RMelt7t6VlDpjO5iSyr/FcxXo0zfCAFXvk FT6ceZ+b/iygU/ZJ6UXCNPw8Gnf7Ev7/PWLIZxMI= From: "zfigura at codeweavers dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/111107] New: i686-w64-mingw32 does not realign stack when __attribute__((aligned)) or __attribute__((vector_size)) are used Date: Tue, 22 Aug 2023 21:27:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: ABI, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: zfigura at codeweavers dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone cf_gcctarget Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111107 Bug ID: 111107 Summary: i686-w64-mingw32 does not realign stack when __attribute__((aligned)) or __attribute__((vector_size)) are used Product: gcc Version: 12.2.0 Status: UNCONFIRMED Keywords: ABI, wrong-code Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: zfigura at codeweavers dot com Target Milestone: --- Target: i686-w64-mingw32 Minimal example: typedef int myint[4] __attribute__((aligned(16))); extern void g(void *); void f(void) { myint a; g(&a); } The same thing happens if __attribute__((aligned(16))) is applied to the variable instead of the typedef. This seems to also prevent __m128 from being aligned correctly (which uses = the "vector_size" attribute rather than "aligned", but I would assume that "vector_size" implies "aligned"). -mincoming-stack-boundary=3D2 works as a workaround; so does -mstackrealign. Neither should be necessary, though. I've seen some disagreement [1] [2] as to whether the stack alignment for i686-w64-mingw32 *should* be 16 or 4, but as far as I can tell it really sh= ould be 4. It's explicitly called out in a code comment [3]; it shows up when -m= sse2 is used [4], and, well, it reflects the actual ABI of programs that exist in the wild. We do regularly come across programs in Wine that don't align the stack to a 16-byte boundary before calling win32 functions, and while -mstackrealign a= nd similar functions exist, they imply that we either waste time and space unnecessarily aligning *every* function, or we manually align any function = that might use an aligned type, which is in general something that's treated as = the compiler's responsibility. [1] https://github.com/mingw-w64/mingw-w64/issues/30#issuecomment-1685487779 [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110273#c5 [3] https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dblob;f=3Dgcc/config/i386/cygming.h= ;h=3Dd539f8d0699d69b014e9d3378e78d690ea289f14;hb=3DHEAD#l34 [4] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110273#c6=