Bug#1038603: gcc-12 was compiled with BMI instructions, which seems to it sometimes crashing in older CPUs

2023-06-19 Thread Matthias Klose

Control: tags -1 + moreinfo

On 18.06.23 21:41, Jeronimo Pellegrini wrote:

Package: gcc-12
Version: 12.3.0-4
Severity: important

Dear Maintainer,

It seems that the Debian package of GCC 12 was compiled with BMI1 (and
BMI2) instructions (perhaps the wrong -march setting is being
used?). At least apparently (see below). Those are relatively new
instruction sets, and are not supported by older CPUs.

* What led up to the situation?

Compiling darktable from the git repository (I am a darktable
translator, so installing the pre-packaged version doesn't work for
me). I noticed another darktable submitted an issue to darktable:

https://github.com/darktable-org/darktable/issues/14701

and realized it was exactly the same error that occurred when I tried
to compile darktable on my machine.

* What exactly did you do (or not do) that was effective (or
   ineffective)?

Just cloned and tried to compile darktable:

git clone https://github.com/darktable-org/darktable.git
git submodule update
cd darktable
./build.sh --prefix /usr/local --build-type Release

* What was the outcome of this action?

Illegal instruction while compiling:

[ 20%] Building C object bin/CMakeFiles/lib_darktable.dir/common/iop_order.c.o
during GIMPLE pass: graphite
/home/magnus/camera2/test2/darktable-debian12/darktable/src/common/iop_order.c: 
In function ‘_insert_before.isra’:
/home/magnus/camera2/test2/darktable-debian12/darktable/src/common/iop_order.c:404:15:
 internal compiler error: Illegal instruction
   404 | static GList *_insert_before(GList *iop_order_list,
   |   ^~
0x7f1fc963ef8f ???
./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7f1fc962a189 __libc_start_call_main
../sysdeps/nptl/libc_start_call_main.h:58
0x7f1fc962a244 __libc_start_main_impl
../csu/libc-start.c:381
Please submit a full bug report, with preprocessed source (by using 
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
make[2]: *** [bin/CMakeFiles/lib_darktable.dir/build.make:726: 
bin/CMakeFiles/lib_darktable.dir/common/iop_order.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2473: bin/CMakeFiles/lib_darktable.dir/all] 
Error 2
make: *** [Makefile:156: all] Error 2


* What outcome did you expect instead?

Full compilation without problems.

Some more info:

- Clang compiles darktable without problems
- Could not test gcc-11, because 12 is the minimum version that
   the darktable build script accepts
- The darktable issue has some more information on this, incuding
   some guided debugging (a darktable maintainer helped me and
   the issue submitter find the exact problem, which was BMI1 and
   BMI2 instructions being executed during compilation):
   https://github.com/darktable-org/darktable/issues/14701

For me the illegal instruction was blsr, and for the issue submitter,
it was shlx (see the issue).

My CPU is an AMD FX-8320E. The original issue submitter had an Intel
i7-3770K CPU.

The illegal instruction is in 'isl_hash_table_init'. Now, the strange
part is that

grep -r isl_hash_table_init *


the trace above doesn't show anything about isl. Also isl is only used when 
using the graphite options. Unfortunately the darktable build script doesn't 
show any compiler options during the build ...



inside gcc sources doesn't return anything. But as the original
darktable issue reporter mentioned, recompiling GCC manually seems to
fix the issue. For lack of better information, and since recompiling
gcc seems to have fixed the issue for one person, I am submitting this
bug to the gcc-12 package. Sorry if it's not the correct place.

Please tell me if there is anything else I can do to help.


GCC is built without any -march settings on amd64, which means -march=x86-64-v1. 
I rather suspect, darktable is turning on various optimizations on it's own.




Bug#1038603: gcc-12 was compiled with BMI instructions, which seems to it sometimes crashing in older CPUs

2023-06-18 Thread Jeronimo Pellegrini
Package: gcc-12
Version: 12.3.0-4
Severity: important

Dear Maintainer,

It seems that the Debian package of GCC 12 was compiled with BMI1 (and
BMI2) instructions (perhaps the wrong -march setting is being
used?). At least apparently (see below). Those are relatively new
instruction sets, and are not supported by older CPUs.

* What led up to the situation?

Compiling darktable from the git repository (I am a darktable
translator, so installing the pre-packaged version doesn't work for
me). I noticed another darktable submitted an issue to darktable:

https://github.com/darktable-org/darktable/issues/14701

and realized it was exactly the same error that occurred when I tried
to compile darktable on my machine.

* What exactly did you do (or not do) that was effective (or
  ineffective)?

Just cloned and tried to compile darktable:

git clone https://github.com/darktable-org/darktable.git
git submodule update
cd darktable
./build.sh --prefix /usr/local --build-type Release

* What was the outcome of this action?

Illegal instruction while compiling:

[ 20%] Building C object bin/CMakeFiles/lib_darktable.dir/common/iop_order.c.o
during GIMPLE pass: graphite
/home/magnus/camera2/test2/darktable-debian12/darktable/src/common/iop_order.c: 
In function ‘_insert_before.isra’:
/home/magnus/camera2/test2/darktable-debian12/darktable/src/common/iop_order.c:404:15:
 internal compiler error: Illegal instruction
  404 | static GList *_insert_before(GList *iop_order_list,
  |   ^~
0x7f1fc963ef8f ???
./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7f1fc962a189 __libc_start_call_main
../sysdeps/nptl/libc_start_call_main.h:58
0x7f1fc962a244 __libc_start_main_impl
../csu/libc-start.c:381
Please submit a full bug report, with preprocessed source (by using 
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
make[2]: *** [bin/CMakeFiles/lib_darktable.dir/build.make:726: 
bin/CMakeFiles/lib_darktable.dir/common/iop_order.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2473: bin/CMakeFiles/lib_darktable.dir/all] 
Error 2
make: *** [Makefile:156: all] Error 2


* What outcome did you expect instead?

Full compilation without problems.

Some more info:

- Clang compiles darktable without problems
- Could not test gcc-11, because 12 is the minimum version that
  the darktable build script accepts
- The darktable issue has some more information on this, incuding
  some guided debugging (a darktable maintainer helped me and
  the issue submitter find the exact problem, which was BMI1 and
  BMI2 instructions being executed during compilation):
  https://github.com/darktable-org/darktable/issues/14701

For me the illegal instruction was blsr, and for the issue submitter,
it was shlx (see the issue).

My CPU is an AMD FX-8320E. The original issue submitter had an Intel
i7-3770K CPU.

The illegal instruction is in 'isl_hash_table_init'. Now, the strange
part is that

grep -r isl_hash_table_init *

inside gcc sources doesn't return anything. But as the original
darktable issue reporter mentioned, recompiling GCC manually seems to
fix the issue. For lack of better information, and since recompiling
gcc seems to have fixed the issue for one person, I am submitting this
bug to the gcc-12 package. Sorry if it's not the correct place.

Please tell me if there is anything else I can do to help.

Thank you!
Jeronimo

-- System Information:
Debian Release: trixie/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.0-9-amd64 (SMP w/8 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_US:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages gcc-12 depends on:
ii  binutils   2.40.50.20230611-2
ii  cpp-12 12.3.0-4
ii  gcc-12-base12.3.0-4
ii  libc6  2.36-9
ii  libcc1-0   13.1.0-6
ii  libgcc-12-dev  12.3.0-4
ii  libgcc-s1  13.1.0-6
ii  libgmp10   2:6.2.1+dfsg1-1.1
ii  libisl23   0.26-2
ii  libmpc31.3.1-1
ii  libmpfr6   4.2.0-1
ii  libstdc++6 13.1.0-6
ii  libzstd1   1.5.4+dfsg2-5
ii  zlib1g 1:1.2.13.dfsg-1

Versions of packages gcc-12 recommends:
ii  libc6-dev  2.36-9

Versions of packages gcc-12 suggests:
ii  gcc-12-doc   12.2.0-1
pn  gcc-12-locales   
ii  gcc-12-multilib  12.3.0-4

-- no debconf information