psmedley / gcc

GNU General Public License v2.0
7 stars 1 forks source link

Broken SSE2 register alignment #6

Open dmik opened 10 years ago

dmik commented 10 years ago

SSE2 builtins enabled with -msse2 use m128i (16-byte) variables to execute SSE2 instructions. This variables must be aligned on a 4 word boundary — otherwise the CPU will generate an access violation exception (SIGSEGV). However, GCC for OS/2 fails to do so — it doesn't perform any special alignment on them (which usually makes them aligned on a word (4 byte) boundary). This is wrong and needs to be fixed.

The version of GCC affected is at least 4.4.x. (including 4.4.6). More details are here http://trac.netlabs.org/qt4/ticket/187 and here https://github.com/bitwiseworks/mozilla-os2/issues/29#issuecomment-40537774.

StevenLevine commented 10 years ago

I wonder if the best long term solution would be to force stack realign whenever building with SSE2 enabled so we match the Linux semantics. It should be possible to tweak the specs to add -mstackrealign anytime -msse2 is present.

psmedley commented 10 years ago

Hi,

On 18/04/14 04:25, StevenLevine wrote:

I wonder if the best long term solution would be to force stack realign whenever building with SSE2 enabled so we match the Linux semantics. It should be possible to tweak the specs to add -mstackrealign anytime -msse2 is present.

I don't disagree - but it seems other platforms have similar issues, see: https://bugs.ruby-lang.org/issues/8349 https://qt.gitorious.org/qt/qtbase/source/25e7fe16504ad4784ea2d75204ffa855ca6d3e1b:mkspecs/win32-g++/qmake.conf https://bugzilla.mozilla.org/show_bug.cgi?id=631252

psmedley commented 8 years ago

There's a possible fix for this in GCC 6.1.0 - I just applied the following from cygming.h to emx.h: /* 32-bit Windows aligns the stack on a 4-byte boundary but SSE instructions may require 16-byte alignment. */

undef STACK_REALIGN_DEFAULT

define STACK_REALIGN_DEFAULT TARGET_SSE

Is there a simple testcase?

psmedley commented 7 years ago

I rebuilt qtgui4.dll with GCC 6.2.0 without using -mstackrealign and can't reproduce https://trac.netlabs.org/qt4/ticket/187