public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/111107] New: i686-w64-mingw32 does not realign stack when __attribute__((aligned)) or __attribute__((vector_size)) are used
@ 2023-08-22 21:27 zfigura at codeweavers dot com
  2023-08-22 21:29 ` [Bug target/111107] " pinskia at gcc dot gnu.org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: zfigura at codeweavers dot com @ 2023-08-22 21:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111107

            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=2 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 should
be 4. It's explicitly called out in a code comment [3]; it shows up when -msse2
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 and
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=110273#c5
[3]
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/i386/cygming.h;h=d539f8d0699d69b014e9d3378e78d690ea289f14;hb=HEAD#l34
[4] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110273#c6

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

end of thread, other threads:[~2023-11-29 19:05 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-22 21:27 [Bug target/111107] New: i686-w64-mingw32 does not realign stack when __attribute__((aligned)) or __attribute__((vector_size)) are used zfigura at codeweavers dot com
2023-08-22 21:29 ` [Bug target/111107] " pinskia at gcc dot gnu.org
2023-08-22 21:41 ` zfigura at codeweavers dot com
2023-08-22 21:41 ` pinskia at gcc dot gnu.org
2023-08-22 21:56 ` zfigura at codeweavers dot com
2023-08-23  7:55 ` rguenth at gcc dot gnu.org
2023-08-24 20:29 ` zfigura at codeweavers dot com
2023-08-28 18:28 ` gabrielopcode at gmail dot com
2023-11-25  7:34 ` alexhenrie24 at gmail dot com
2023-11-25  8:57 ` amonakov at gcc dot gnu.org
2023-11-25 17:40 ` gabrielopcode at gmail dot com
2023-11-25 18:54 ` alexhenrie24 at gmail dot com
2023-11-25 19:20 ` alexhenrie24 at gmail dot com
2023-11-25 21:45 ` alexhenrie24 at gmail dot com
2023-11-28 22:34 ` ebotcazou at gcc dot gnu.org
2023-11-28 22:58 ` ebotcazou at gcc dot gnu.org
2023-11-29  3:54 ` zfigura at codeweavers dot com
2023-11-29  7:49 ` ebotcazou at gcc dot gnu.org
2023-11-29 19:05 ` zfigura at codeweavers dot com

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).