Re: Misalignment of local SSE variables in thread function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andrew Haley wrote:

>  > So, neither CreateThread nor MSVCRT align the stack, so I guess you'll
>  > have to do it yourself.  You should be able to do this with something
>  > like:
>  >
>  >   asm  __volatile__  ("andl $-16, %%esp" : : : "%esp");
>  >
>  > at the beginning of your thread function.
> 
> Ouch.  I don't think that would work.

It looked a little iffy to me too, but I copied it directly from mingw's
crt1.c where it has this comment:

  /* Align the stack to 16 bytes for the sake of SSE ops in main
     or in functions inlined into main.  */

>  > You could probably do this in a wrapper-function that calls your
>  > actual thread function too.
> 
> That sounds like a much better idea, although it may well also be
> problematic.
> 
> A pure assembly function that did the adjustment and called your
> actual thread function would be the best idea.

Undoutably that would be better.  The problem from the MinGW standpoint
is that unlike the main thread where we can control the crt1.o stuff,
when creating a thread we have no control over what happens since MSVCRT
is a black box written by Microsoft which assumes MS's compiler which I
guess does not require aligned stacks in threads.  Perhaps MinGW should
reimplement a _beginthread replacement that calls MSVCRT's _beginthread,
with the thread entry point set to a wrapper function that sets the
alignment and then calls the user entry point.  This is highly ironic
because this is exactly what _beginthread itself is doing -- a wrapper
around CreateThread that creates the thread with the entry point set to
a MSVCRT wrapper function that inits MSVCRT-private data structures for
the thread and then calls the user entrypoint.

Brian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux