segfault when using mercury bootstrapped with gcc 12.x
keriharris opened this issue · 4 comments
mmc segfaults when mercury_compile has been bootstrapped with gcc 12.x. The following steps reproduce this on Ubuntu Linux 22.04 LTS:
install gcc 12
sudo apt-get install gcc-12
compile mercury using gcc 12
$ ./configure --with-cc=/usr/bin/gcc-12 --disable-most-grades --disable-debug-grades --prefix=/path/to/mercury
...
checking for mmc... no
...
$ make && make install
compile mercury_compile using mercury built with gcc 12
$ make clean
$ ./configure --with-cc=/usr/bin/gcc-12 --disable-most-grades --disable-debug-grades
...
checking for mmc... /path/to/mercury/bin/mmc
...
$ make
use mercury_compile bootstrapped with gcc 12
$ cd ssdb
$ touch *.m
$ mmake MERCURY_COMPILER=../compiler/mercury_compile
/path/to/mercury/bin/mmc --make-interface --grade asm_fast.gc --mercury-linkage shared -R/path/to/mercury/lib/mercury/lib/asm_fast.gc -R/path/to/mercury/lib/mercury/lib --flags SSDB_FLAGS ssdb
*** Mercury runtime: caught strange segmentation violation ***
PC at signal: 94736851939600 (5629a4683110)
This may have been caused by a stack overflow, due to unbounded recursion.
gmake: *** [/tmp/mmake.QMBUCs:1947: ssdb.date] Error 1
Which version of Mercury? Your error report contains no specifics that would differentiate this issue
from issue #102, which has been fixed in the latest rotd and the updated release version.
The segfault occurs with mercury rotd 2022-06-19 (which contains the fix for #102).
This appears to be due to some interaction between the code we generate in asm_fast
grades and GCC's auto-vectorization optimisations. It also arises with GCC 11 if you compile with -O3
or with -ftree-vectorize
.
The workaround (at least for now) is to always compile with -fno-tree-vectorize
. (I have successfully bootchecked the system with GCC 12 in asm_fast.gc
with that option.) I'll add something to the configure
script after I've checked
some other grades and determined which of the auto-vectorization options is causing the problem .
I have a small test case for this based on tests/general/higher_order.m
-- I'll add that Mantis shortly along with
the assembly listings for GCC 11 and GCC12.
There's a workaround available in 22.01.3-beta-2022-06-27
and rotd-2022-06-25
.
Anything further about this issue will be covered in Mantis #561.