Bug 216563 - lang/gcc5: lang/gcc: stack alignment insufficient on i386 for SSE2 code.
Summary: lang/gcc5: lang/gcc: stack alignment insufficient on i386 for SSE2 code.
Status: Closed Overcome By Events
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: i386 Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords: crash, needs-qa
Depends on:
Blocks:
 
Reported: 2017-01-29 01:57 UTC by Matthias Andree
Modified: 2019-10-30 13:28 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Andree freebsd_committer freebsd_triage 2017-01-29 01:57:19 UTC
GCC 5.4.0 and also 4.9.0 from ports fail to generate working code for rawtherapee, a C++11 application, and cause it to drop core with a SIGBUS on i386. This is with -O3 -msse2.  

amd64 is unaffected. Other architectures are untested. GCC 6 and 7-devel are untested.

To reproduce, compile ports/heads/graphics/rawtherapee-devel as of r432608 (exactly this version!), add "CFLAGS+=-g" and "STRIP=" to the Makefile and see that it is hit by a SIGBUS in post-install when it tries to check if the program is able to start. DO NOT USE WITH_DEBUG=yes, that will change compiler flags and mask the bug!

Debugging this reveals that the generated code crashes when initalizing an auto double[8] = { ... } vector upon entry to the function, when it tries to copy it around with SSE instructions that require 16-byte alignment, but the source address has some 0x...8 address. This affects i386 on 10.3-RELEASE and 11.0-RELEASE (both fully patched).

I am reporting this against GCC because this does NOT happen when the code is recompiled with base clang (3.4.0 for FreeBSD 10.3, or 3.8.0 for FreeBSD 11.0.) without changing anything else on the system (in particular, gdk, gtk, ... are NOT touched when switching compilers).

Workaround: add -mstackrealign.
Comment 1 Gerald Pfeifer freebsd_committer freebsd_triage 2017-08-13 21:34:15 UTC
I'm sorry we have not been able to get back to this with a change/fix.

In our e-mail conversation in January dim@ pointed out that this is a
tricky one upstream, cf.

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

and is unlikely to be addressed, so what you did, Matthias, in
graphics/rawtherapee/Makefile is the best I can think of, either.
Comment 2 Matthias Andree freebsd_committer freebsd_triage 2019-05-12 07:50:24 UTC
Wow. The original bug reports are 10 years old.  You could've thought this has been fixed long since.

The interesting part is that the affected code line per se deals with an array of double values, so that should be happy with 4-byte aligned stacks, but some part of the code employs SSE2 code to initialize the array and that copy-initial-values-code requires 16-byte alignment. Something in the compiler is inconsistent. Either it needs to figure it can't rely on the alignment of the stack - then it cannot use SSE2 instructions, or, if it wants to use SSE2 instructions, it needs to waste 4...12 bytes but make realignment automatic.
Comment 3 Rene Ladan freebsd_committer freebsd_triage 2019-10-30 13:28:13 UTC
Expired port removed.