Bug 264979

Summary: archivers/c-blosc2: compiler crash
Product: Ports & Packages Reporter: Robert Clausecker <fuz>
Component: Individual Port(s)Assignee: Po-Chuan Hsieh <sunpoet>
Status: Closed Overcome By Events    
Severity: Affects Some People CC: dim, dmgk, fuz, marklmi26-fbsd, pkubaj, toolchain
Priority: --- Flags: bugzilla: maintainer-feedback? (sunpoet)
Version: Latest   
Hardware: Any   
OS: Any   
URL: https://github.com/llvm/llvm-project/issues/56337

Description Robert Clausecker freebsd_committer freebsd_triage 2022-07-01 15:54:03 UTC
Building this port causes a compiler crash on armv7.  The crash has been reduced with creduce to the following minimal test case:

    extern int a, d, i[], e[];
    _Noreturn int c(void);
    void f()
    {
            d <= 3 ? 0 : c();
            for (int h = 1; h < d; ++h)
                     i[h] = a % e[h - 1] / e[h];
    }

The crash is due to a SIGBUS (unaligned memory access?) and might be the same thing that happened on PPC64 (pkubaj@, please check).  I'll go ahead and report it with upstream.

As a stop gap measure, the port should be compiled with gcc on armv7, too.
Comment 1 Robert Clausecker freebsd_committer freebsd_triage 2022-07-01 16:10:29 UTC
Upstream issue has been filed:

https://github.com/llvm/llvm-project/issues/56337
Comment 2 Dmitri Goutnik freebsd_committer freebsd_triage 2022-07-01 16:32:38 UTC
Also reproducible on 14.0-CURRENT amd64 with both /usr/bin/cc (clang 14.0.5) and /usr/local/bin/clang{13,14}.
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2022-07-01 20:32:22 UTC
Upstream has a fix for this crash (actually an assertion, if assertions are enabled). I will proceed to merge the fix into -CURRENT, and MFC it.
Comment 4 Robert Clausecker freebsd_committer freebsd_triage 2022-07-01 21:41:42 UTC
(In reply to Dimitry Andric from comment #3)

Please note that this is a PR against a port, so don't close it until you have fixed the port.  Fixing this in CURRENT or even 13-STABLE is not going to cause the port to start building all of the sudden.  If you want to track backporting the compiler patch, please make a separate PR.
Comment 5 Dimitry Andric freebsd_committer freebsd_triage 2022-07-01 22:02:24 UTC
Oh okay, fine with me. So maybe the port can be fixed in the mean time by patching out some code, or lowering the optimization level?
Comment 6 Robert Clausecker freebsd_committer freebsd_triage 2022-07-01 22:31:48 UTC
(In reply to Dimitry Andric from comment #5)

Easiest would be to compile it with gcc.  There's already a conditional for that in the Makefile to do that on PPC.  Will send you a patch shortly to extend this to armv7.
Comment 7 commit-hook freebsd_committer freebsd_triage 2022-07-01 23:16:14 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=836d47d38e0a586c9b307fd7fb46bf563acba151

commit 836d47d38e0a586c9b307fd7fb46bf563acba151
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2022-07-01 23:13:46 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2022-07-01 23:13:46 +0000

    Apply llvm fix for assertion/crash building archivers/c-blosc2

    Merge commit 88ce403c6aab from llvm git (by Florian Hahn):

      [LV] Add new block to place recurrence splice, if needed.

      In some cases, a recurrence splice instructions needs to be inserted
      between to regions, for example if the regions get re-arranged during
      sinking.

      Fixes #56146.

    PR:             264979
    Reported by:    Robert Clausecker <fuz@fuz.su>
    MFC after:      3 days

 .../llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp    | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Comment 8 Robert Clausecker freebsd_committer freebsd_triage 2022-07-02 06:14:33 UTC
Tested a patch that extends pkubaj@'s use of gcc to armv?.  While this causes the port to build, now the test suite fails with lots of bus errors.  Will have to investigate this further.
Comment 9 Mark Millard 2022-07-02 08:34:48 UTC
(In reply to Robert Clausecker from comment #8)

What does ldd report about the installed program(s)?
Comment 10 Robert Clausecker freebsd_committer freebsd_triage 2022-07-02 13:57:30 UTC
(In reply to Mark Millard from comment #9)

I'm not sure what you mean, could you be more specific?
Comment 11 Mark Millard 2022-07-02 14:20:45 UTC
(In reply to Robert Clausecker from comment #10)

Bad combination ( wrong libgcc_s.so.1 ):

# g++11 trivial.cpp
# ldd a.out
a.out:
       libstdc++.so.6 => /usr/local/lib/gcc11/libstdc++.so.6 (0x42600000)
       libm.so.5 => /lib/libm.so.5 (0x40c8a000)
       libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x419b2000)
       libc.so.7 => /lib/libc.so.7 (0x430fe000)

Various type of programs can have crash problems from
such a mix.

Good combination:

# g++11 -Wl,-rpath=/usr/local/lib/gcc11 trivial.cpp
# ldd a.out
a.out:
       libstdc++.so.6 => /usr/local/lib/gcc11/libstdc++.so.6 (0x42400000)
       libm.so.5 => /lib/libm.so.5 (0x409a9000)
       libgcc_s.so.1 => /usr/local/lib/gcc11/libgcc_s.so.1 (0x41072000)
       libc.so.7 => /lib/libc.so.7 (0x43f5a000)

(The examples are from an old bugzilla report's comments.)

I was just curious about what was involved in your failing context
(the port's gcc based build).
Comment 12 commit-hook freebsd_committer freebsd_triage 2022-07-05 18:23:35 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=92f7d05dd251b111913d642a8562567bcbd9b539

commit 92f7d05dd251b111913d642a8562567bcbd9b539
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2022-07-01 23:13:46 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2022-07-05 18:22:20 +0000

    Apply llvm fix for assertion/crash building archivers/c-blosc2

    Merge commit 88ce403c6aab from llvm git (by Florian Hahn):

      [LV] Add new block to place recurrence splice, if needed.

      In some cases, a recurrence splice instructions needs to be inserted
      between to regions, for example if the regions get re-arranged during
      sinking.

      Fixes #56146.

    PR:             264979
    Reported by:    Robert Clausecker <fuz@fuz.su>
    MFC after:      3 days

    (cherry picked from commit 836d47d38e0a586c9b307fd7fb46bf563acba151)

 .../llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp    | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Comment 13 Robert Clausecker freebsd_committer freebsd_triage 2022-07-06 17:09:04 UTC
I've now managed to reproduce the problem on amd64 FreeBSD 13.1, so it's not an arm exclusive issue.
Might be best to just USE_GCC the port and be done with it.

[  3% 14/361] /usr/bin/cc -DBLOSC_SHARED_LIBRARY -DUSING_CMAKE -Dblosc2_shared_EXPORTS -I/wrkdirs/usr/ports/archivers/c-blosc2/work/.build/blosc -I/wrkdirs/usr/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/include -I/wrkdirs/usr/ports/archi
vers/c-blosc2/work/c-blosc2-2.1.1/plugins/codecs/zfp/include -I/wrkdirs/usr/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/blosc -I/usr/local/include -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing -std=gnu99 -D_XOPEN_SOURCE=600 -O2
 -pipe  -fstack-protector-strong -fno-strict-aliasing -fPIC -fvisibility=hidden -Wall -Wextra -pthread -MD -MT blosc/CMakeFiles/blosc2_shared.dir/__/plugins/codecs/zfp/blosc2-zfp.c.o -MF blosc/CMakeFiles/blosc2_shared.dir/__/plugins/codecs
/zfp/blosc2-zfp.c.o.d -o blosc/CMakeFiles/blosc2_shared.dir/__/plugins/codecs/zfp/blosc2-zfp.c.o -c /wrkdirs/usr/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/plugins/codecs/zfp/blosc2-zfp.c
FAILED: blosc/CMakeFiles/blosc2_shared.dir/__/plugins/codecs/zfp/blosc2-zfp.c.o 
/usr/bin/cc -DBLOSC_SHARED_LIBRARY -DUSING_CMAKE -Dblosc2_shared_EXPORTS -I/wrkdirs/usr/ports/archivers/c-blosc2/work/.build/blosc -I/wrkdirs/usr/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/include -I/wrkdirs/usr/ports/archivers/c-blosc2/
work/c-blosc2-2.1.1/plugins/codecs/zfp/include -I/wrkdirs/usr/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/blosc -I/usr/local/include -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing -std=gnu99 -D_XOPEN_SOURCE=600 -O2 -pipe  -fstac
k-protector-strong -fno-strict-aliasing -fPIC -fvisibility=hidden -Wall -Wextra -pthread -MD -MT blosc/CMakeFiles/blosc2_shared.dir/__/plugins/codecs/zfp/blosc2-zfp.c.o -MF blosc/CMakeFiles/blosc2_shared.dir/__/plugins/codecs/zfp/blosc2-zf
p.c.o.d -o blosc/CMakeFiles/blosc2_shared.dir/__/plugins/codecs/zfp/blosc2-zfp.c.o -c /wrkdirs/usr/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/plugins/codecs/zfp/blosc2-zfp.c
PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /usr/bin/cc -DBLOSC_SHARED_LIBRARY -DUSING_CMAKE -Dblosc2_shared_EXPORTS -I/wrkdirs/usr/ports/archivers/c-blosc2/work/.build/blosc -I/wrkdirs/usr/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/include -I/wrkdirs/us
r/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/plugins/codecs/zfp/include -I/wrkdirs/usr/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/blosc -I/usr/local/include -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -std=gnu99 -D_XOPEN_SO
URCE=600 -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -fPIC -fvisibility=hidden -Wall -Wextra -pthread -MD -MT blosc/CMakeFiles/blosc2_shared.dir/__/plugins/codecs/zfp/blosc2-zfp.c.o -MF blosc/CMakeFiles/blosc2_shared.dir/__/plu
gins/codecs/zfp/blosc2-zfp.c.o.d -o blosc/CMakeFiles/blosc2_shared.dir/__/plugins/codecs/zfp/blosc2-zfp.c.o -c /wrkdirs/usr/ports/archivers/c-blosc2/work/c-blosc2-2.1.1/plugins/codecs/zfp/blosc2-zfp.c
1.      <eof> parser at end of file
2.      Optimizer
 #0 0x00000000048a7860 (/usr/bin/cc+0x48a7860)
 #1 0x00000000048a5cd5 (/usr/bin/cc+0x48a5cd5)
 #2 0x0000000004842033 (/usr/bin/cc+0x4842033)
 #3 0x0000000805be8580 (/lib/libthr.so.3+0x1a580)
 #4 0x0000000805be7b3f (/lib/libthr.so.3+0x19b3f)
 #5 0x00007ffffffff8a3 ([vdso]+0x2d3)
 #6 0x0000000005ad25c5 (/usr/bin/cc+0x5ad25c5)
 #7 0x0000000005a74be7 (/usr/bin/cc+0x5a74be7)
 #8 0x0000000005a6cd69 (/usr/bin/cc+0x5a6cd69)
 #9 0x0000000005a6c210 (/usr/bin/cc+0x5a6c210)
#10 0x0000000005a7960f (/usr/bin/cc+0x5a7960f)
#11 0x0000000005a7d295 (/usr/bin/cc+0x5a7d295)
#12 0x0000000005a7d7b4 (/usr/bin/cc+0x5a7d7b4)
#13 0x000000000475da52 (/usr/bin/cc+0x475da52)
#14 0x0000000004565c82 (/usr/bin/cc+0x4565c82)
#15 0x000000000294b312 (/usr/bin/cc+0x294b312)
#16 0x00000000045680aa (/usr/bin/cc+0x45680aa)
#17 0x000000000294dd22 (/usr/bin/cc+0x294dd22)
#18 0x0000000004564ee7 (/usr/bin/cc+0x4564ee7)
#19 0x00000000029428cf (/usr/bin/cc+0x29428cf)
#20 0x000000000293d87e (/usr/bin/cc+0x293d87e)
#21 0x0000000002bf955f (/usr/bin/cc+0x2bf955f)
#22 0x0000000003030e34 (/usr/bin/cc+0x3030e34)
#23 0x0000000002b509b6 (/usr/bin/cc+0x2b509b6)
#24 0x0000000002ad68e6 (/usr/bin/cc+0x2ad68e6)
#25 0x0000000002bf3827 (/usr/bin/cc+0x2bf3827)
#26 0x0000000002215070 (/usr/bin/cc+0x2215070)
#27 0x0000000002221ac5 (/usr/bin/cc+0x2221ac5)
#28 0x00000000029ac907 (/usr/bin/cc+0x29ac907)
#29 0x0000000004841dca (/usr/bin/cc+0x4841dca)
#30 0x00000000029ac585 (/usr/bin/cc+0x29ac585)
#31 0x000000000297f8e1 (/usr/bin/cc+0x297f8e1)
#32 0x000000000297fd1f (/usr/bin/cc+0x297fd1f)
#33 0x0000000002992c8c (/usr/bin/cc+0x2992c8c)
cc: error: clang frontend command failed with exit code 138 (use -v to see invocation)
FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
Target: x86_64-unknown-freebsd13.1
Thread model: posix
InstalledDir: /usr/bin
cc: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
cc: note: diagnostic msg: /tmp/blosc2-zfp-6bfdc5.c
cc: note: diagnostic msg: /tmp/blosc2-zfp-6bfdc5.sh
cc: note: diagnostic msg: 

********************
ninja: build stopped: subcommand failed.
*** Error code 1

Stop.
make: stopped in /usr/ports/archivers/c-blosc2
=>> Cleaning up wrkdir
===>  Cleaning for c-blosc2-2.1.1
build of archivers/c-blosc2 | c-blosc2-2.1.1 ended at Mon Jul  4 10:08:43 CEST 2022
build time: 00:00:13
Comment 14 Mark Millard 2022-07-06 19:03:48 UTC
(In reply to Robert Clausecker from comment #13)

> Might be best to just USE_GCC the port and be done with it

Did you get past having the test-suite bus errors reported
in comment 8 for gcc-based builds?
Comment 15 Robert Clausecker freebsd_committer freebsd_triage 2022-07-06 19:35:43 UTC
(In reply to Mark Millard from comment #14)

No, I did not investigate further as other things caught my attention.  I did check the rpath though and that was not the problem.  I don't know if the same
test suite failure occurs on other architectures; might be worth checking (just run make test in the port directory).
Comment 16 Po-Chuan Hsieh freebsd_committer freebsd_triage 2022-07-07 22:22:59 UTC
I've updated archivers/c-blosc2 to 2.2.0. I did not encounter build failure with this version on both 12.3 & 13.1 amd64.
Comment 17 Robert Clausecker freebsd_committer freebsd_triage 2022-09-28 00:10:13 UTC
Compiler crash no longer occurs.