Bug 271624 - emulators/qmc2: clang crashes during build on {12.4,13.1}-arm64-quarterly
Summary: emulators/qmc2: clang crashes during build on {12.4,13.1}-arm64-quarterly
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-ports-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-05-25 04:49 UTC by Alastair Hogge
Modified: 2023-07-15 01:34 UTC (History)
5 users (show)

See Also:
fernape: maintainer-feedback? (toolchain)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Comment 1 Alastair Hogge 2023-05-25 04:52:02 UTC
fatal error: error in backend: Cannot select: intrinsic %llvm.aarch64.crc32b
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: cc -c -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -DUSE_FILE32API -O2 -w -pthread -fPIC -DQMC2_ARCADE_RELEASE -DQMC2_ARCADE_BUNDLED_MINIZIP -DQMC2_ARCADE_BUNDLED_ZLIB -DQMC2_ARCADE -DHAVE_ZLIB -DZLIB_COMPAT -D_7ZIP_PPMD_SUPPORT -D_7ZIP_ST -DQMC2_ARCADE_VERSION=0.243 -DQMC2_ARCADE_MAIN_UI_VERSION=0.243 -DQMC2_ARCADE_ENABLE_JOYSTICK -DQMC2_ARCADE_QML_IMPORT_PATH=imports -DQT_NO_DEBUG -DQT_SVG_LIB -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_QMLMODELS_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_TESTLIB_LIB -DQT_CORE_LIB -DQT_TESTCASE_BUILDDIR=\"/wrkdirs/usr/ports/emulators/qmc2/work/qmc2-mame-fe-0.243/src/arcade\" -I. -I../lzma -I../minizip -I../zlib -I/usr/local/include/SDL2 -I/usr/local/include -I/usr/local/include/qt5 -I/usr/local/include/qt5/QtSvg -I/usr/local/include/qt5/QtOpenGL -I/usr/local/include/qt5/QtWidgets -I/usr/local/include/qt5/QtQuick -I/usr/local/include/qt5/QtGui -I/usr/local/include/qt5/QtSql -I/usr/local/include/qt5/QtQmlModels -I/usr/local/include/qt5/QtQml -I/usr/local/include/qt5/QtNetwork -I/usr/local/include/qt5/QtTest -I/usr/local/include/qt5/QtCore -I. -I/usr/local/include -I/usr/local/include -I/usr/local/lib/qt5/mkspecs/freebsd-clang -o 7zCrc.o ../lzma/7zCrc.c
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '../lzma/7zCrc.c'.
4.	Running pass 'AArch64 Instruction Selection' on function '@CrcUpdateT0_32'
c++ -c -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -DUSE_FILE32API -O2 -w -pthread -fPIC -DQCHDMAN_RELEASE -DQCHDMAN_VERSION=0.243 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SCRIPT_LIB -DQT_SCRIPTTOOLS_LIB -DQT_CORE_LIB -I. -I/usr/local/include/qt5 -I/usr/local/include/qt5/QtWidgets -I/usr/local/include/qt5/QtGui -I/usr/local/include/qt5/QtScript -I/usr/local/include/qt5/QtScriptTools -I/usr/local/include/qt5/QtCore -I. -I/usr/local/include -I. -I/usr/local/include -I/usr/local/lib/qt5/mkspecs/freebsd-clang -o settings.o ../../settings.cpp
 #0 0x0000000004112678 (/usr/bin/cc+0x4112678)
 #1 0x0000000004110abc (/usr/bin/cc+0x4110abc)
 #2 0x00000000040b4d30 (/usr/bin/cc+0x40b4d30)
 #3 0x00000000040b4cb8 (/usr/bin/cc+0x40b4cb8)
 #4 0x000000000410b2e0 (/usr/bin/cc+0x410b2e0)
 #5 0x0000000001e09414 (/usr/bin/cc+0x1e09414)
 #6 0x00000000040bb874 (/usr/bin/cc+0x40bb874)
 #7 0x00000000040bb964 (/usr/bin/cc+0x40bb964)
 #8 0x000000000436e290 (/usr/bin/cc+0x436e290)
 #9 0x000000000436d964 (/usr/bin/cc+0x436d964)
#10 0x00000000044e2de0 (/usr/bin/cc+0x44e2de0)
#11 0x0000000004367e24 (/usr/bin/cc+0x4367e24)
#12 0x0000000004367690 (/usr/bin/cc+0x4367690)
#13 0x0000000004366d44 (/usr/bin/cc+0x4366d44)
#14 0x0000000004364fd0 (/usr/bin/cc+0x4364fd0)
#15 0x0000000003a94ce8 (/usr/bin/cc+0x3a94ce8)
#16 0x0000000003e04a94 (/usr/bin/cc+0x3e04a94)
#17 0x0000000003e0a214 (/usr/bin/cc+0x3e0a214)
#18 0x0000000003e04fa0 (/usr/bin/cc+0x3e04fa0)
#19 0x00000000024ac818 (/usr/bin/cc+0x24ac818)
#20 0x00000000024a8a1c (/usr/bin/cc+0x24a8a1c)
#21 0x00000000026faf98 (/usr/bin/cc+0x26faf98)
#22 0x0000000002b0cf44 (/usr/bin/cc+0x2b0cf44)
#23 0x0000000002660b98 (/usr/bin/cc+0x2660b98)
#24 0x0000000002604c9c (/usr/bin/cc+0x2604c9c)
#25 0x00000000026f6534 (/usr/bin/cc+0x26f6534)
#26 0x0000000001e09180 (/usr/bin/cc+0x1e09180)
#27 0x0000000001e14478 (/usr/bin/cc+0x1e14478)
#28 0x00000000025093f8 (/usr/bin/cc+0x25093f8)
#29 0x00000000040b4c8c (/usr/bin/cc+0x40b4c8c)
#30 0x000000000250905c (/usr/bin/cc+0x250905c)
#31 0x00000000024e3548 (/usr/bin/cc+0x24e3548)
#32 0x00000000024e38f0 (/usr/bin/cc+0x24e38f0)
#33 0x00000000024f36c4 (/usr/bin/cc+0x24f36c4)
cc: error: clang frontend command failed with exit code 70 (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: aarch64-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/7zCrc-bf1673.c
cc: note: diagnostic msg: /tmp/7zCrc-bf1673.sh
cc: note: diagnostic msg:
Comment 2 Alastair Hogge 2023-05-29 01:34:01 UTC
Log for 12.4:
https://pkg-status.freebsd.org/ampere1/data/124arm64-quarterly/34e963521193/logs/qmc2-0.243_1.log
Same "fatal error: error in backend: Cannot select: intrinsic %llvm.aarch64.crc32b"
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2023-05-29 09:12:30 UTC
Can somebody lift out the /tmp/7zCrc-bf1673.c and /tmp/7zCrc-bf1673.sh files, and post them here?
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2023-05-29 12:43:40 UTC
(In reply to Dimitry Andric from comment #3)
Never mind, this is https://github.com/llvm/llvm-project/issues/57802 which is only in clang 16. I will see about patching it into main and MFC'ing it.

As a temporary workaround, the __builtin_arm_crc32b() function could be avoided on arm CPUs that do not support it.
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-05-29 14:29:30 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8792c03886d9e6df10fbac825819603dc059c7ea

commit 8792c03886d9e6df10fbac825819603dc059c7ea
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-05-29 14:27:58 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-05-29 14:28:18 +0000

    Apply clang fixes for crashes compiling ARM/AArch64 CRC intrinsics

    Merge commit 069ecd0c6e2c from llvm-project (by Fangrui Song):

      [ARM] Check target feature support for __builtin_arm_crc*

      `__builtin_arm_crc*` requires the target feature crc which is available on armv8
      and above. Calling the fuctions for armv7 leads to a SelectionDAG crash.

      ```
      % clang -c --target=armv7-unknown-linux-gnueabi -c a.c
      fatal error: error in backend: Cannot select: intrinsic %llvm.arm.crc32b
      PLEASE submit a bug report to ...
      ```

      Add `TARGET_BUILTIN` and define required features for these builtins to
      report an error in `CodeGenFunction::checkTargetFeatures`. The problem is quite widespread.
      I will add `TARGET_BUILTIN` for more builtins later.

      Fix https://github.com/llvm/llvm-project/issues/57802

      Differential Revision: https://reviews.llvm.org/D134127

    Merge commit b2d7a0dcf1ff from llvm-project (by Fangrui Song):

      [AArch64] Check target feature support for __builtin_arm_crc*

      This is the AArch64 counterpart of D134127.
      Daniel Kiss will change more `BUILTIN` to `TARGET_BUILTIN`.

      Fix #57802

    Note that programs attempting to use ARM/AArch64 CRC intrinsics, when
    they are not supported by the targeted CPU, will still receive a regular
    compilation error (instead of a fatal backend error) similar to:

      7zCrc.c:4:10: error: '__builtin_arm_crc32b' needs target feature crc
        return __builtin_arm_crc32b(a, b);
               ^

    Reported by:    Alastair Hogge <agh@riseup.net>
    PR:             271624
    MFC after:      3 days

 .../clang/include/clang/Basic/BuiltinsAArch64.def    | 20 ++++++++++++--------
 .../clang/include/clang/Basic/BuiltinsARM.def        | 20 ++++++++++++--------
 .../llvm-project/clang/lib/Basic/Targets/AArch64.cpp |  2 ++
 contrib/llvm-project/clang/lib/Basic/Targets/ARM.cpp |  2 ++
 4 files changed, 28 insertions(+), 16 deletions(-)
Comment 6 Alastair Hogge 2023-05-30 00:36:36 UTC
Wow, that was quick. Ta very much, Dimitry.
Comment 7 commit-hook freebsd_committer freebsd_triage 2023-06-01 19:17:08 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3cc4f10db0feca9d54bbfc615328b317a5c6b4c8

commit 3cc4f10db0feca9d54bbfc615328b317a5c6b4c8
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-05-29 14:27:58 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-06-01 19:15:31 +0000

    Apply clang fixes for crashes compiling ARM/AArch64 CRC intrinsics

    Merge commit 069ecd0c6e2c from llvm-project (by Fangrui Song):

      [ARM] Check target feature support for __builtin_arm_crc*

      `__builtin_arm_crc*` requires the target feature crc which is available on armv8
      and above. Calling the fuctions for armv7 leads to a SelectionDAG crash.

      ```
      % clang -c --target=armv7-unknown-linux-gnueabi -c a.c
      fatal error: error in backend: Cannot select: intrinsic %llvm.arm.crc32b
      PLEASE submit a bug report to ...
      ```

      Add `TARGET_BUILTIN` and define required features for these builtins to
      report an error in `CodeGenFunction::checkTargetFeatures`. The problem is quite widespread.
      I will add `TARGET_BUILTIN` for more builtins later.

      Fix https://github.com/llvm/llvm-project/issues/57802

      Differential Revision: https://reviews.llvm.org/D134127

    Merge commit b2d7a0dcf1ff from llvm-project (by Fangrui Song):

      [AArch64] Check target feature support for __builtin_arm_crc*

      This is the AArch64 counterpart of D134127.
      Daniel Kiss will change more `BUILTIN` to `TARGET_BUILTIN`.

      Fix #57802

    Note that programs attempting to use ARM/AArch64 CRC intrinsics, when
    they are not supported by the targeted CPU, will still receive a regular
    compilation error (instead of a fatal backend error) similar to:

      7zCrc.c:4:10: error: '__builtin_arm_crc32b' needs target feature crc
        return __builtin_arm_crc32b(a, b);
               ^

    Reported by:    Alastair Hogge <agh@riseup.net>
    PR:             271624
    MFC after:      3 days

    (cherry picked from commit 8792c03886d9e6df10fbac825819603dc059c7ea)

 .../clang/include/clang/Basic/BuiltinsAArch64.def    | 20 ++++++++++++--------
 .../clang/include/clang/Basic/BuiltinsARM.def        | 20 ++++++++++++--------
 .../llvm-project/clang/lib/Basic/Targets/AArch64.cpp |  2 ++
 contrib/llvm-project/clang/lib/Basic/Targets/ARM.cpp |  2 ++
 4 files changed, 28 insertions(+), 16 deletions(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2023-06-01 19:17:09 UTC
A commit in branch stable/12 references this bug:

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

commit dbbac83e39faca07c6081cd549128c253861cdac
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-05-29 14:27:58 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-06-01 19:16:11 +0000

    Apply clang fixes for crashes compiling ARM/AArch64 CRC intrinsics

    Merge commit 069ecd0c6e2c from llvm-project (by Fangrui Song):

      [ARM] Check target feature support for __builtin_arm_crc*

      `__builtin_arm_crc*` requires the target feature crc which is available on armv8
      and above. Calling the fuctions for armv7 leads to a SelectionDAG crash.

      ```
      % clang -c --target=armv7-unknown-linux-gnueabi -c a.c
      fatal error: error in backend: Cannot select: intrinsic %llvm.arm.crc32b
      PLEASE submit a bug report to ...
      ```

      Add `TARGET_BUILTIN` and define required features for these builtins to
      report an error in `CodeGenFunction::checkTargetFeatures`. The problem is quite widespread.
      I will add `TARGET_BUILTIN` for more builtins later.

      Fix https://github.com/llvm/llvm-project/issues/57802

      Differential Revision: https://reviews.llvm.org/D134127

    Merge commit b2d7a0dcf1ff from llvm-project (by Fangrui Song):

      [AArch64] Check target feature support for __builtin_arm_crc*

      This is the AArch64 counterpart of D134127.
      Daniel Kiss will change more `BUILTIN` to `TARGET_BUILTIN`.

      Fix #57802

    Note that programs attempting to use ARM/AArch64 CRC intrinsics, when
    they are not supported by the targeted CPU, will still receive a regular
    compilation error (instead of a fatal backend error) similar to:

      7zCrc.c:4:10: error: '__builtin_arm_crc32b' needs target feature crc
        return __builtin_arm_crc32b(a, b);
               ^

    Reported by:    Alastair Hogge <agh@riseup.net>
    PR:             271624
    MFC after:      3 days

    (cherry picked from commit 8792c03886d9e6df10fbac825819603dc059c7ea)

 .../clang/include/clang/Basic/BuiltinsAArch64.def    | 20 ++++++++++++--------
 .../clang/include/clang/Basic/BuiltinsARM.def        | 20 ++++++++++++--------
 .../llvm-project/clang/lib/Basic/Targets/AArch64.cpp |  2 ++
 contrib/llvm-project/clang/lib/Basic/Targets/ARM.cpp |  2 ++
 4 files changed, 28 insertions(+), 16 deletions(-)
Comment 10 Mark Millard 2023-06-26 02:17:51 UTC
(In reply to Alastair Hogge from comment #9)

No commit to releng/13.1 was made but 131arm64-quarterly runs
builds via a releng/13.1 world. Updating the build servers
for this would require a 13.1-RELEASE-p9 be created and
released first. (The recent -p8 did not include such a
change.)

A similar point goes for releng/12.4 and 124arm64-quarterly.
Comment 11 Mark Millard 2023-06-26 02:25:16 UTC
(In reply to Mark Millard from comment #10)

It looks like the timing worked out such that the point
will also apply to releng/13.2 needing a 13.2-RELEASE-p2 :
13.2-RELEASE(-p0) predates the fixes and the recent
13.2-RELEASE-p1 did not include the fixes.
Comment 12 Alastair Hogge 2023-07-02 00:51:35 UTC
(In reply to Mark Millard from comment #10)
(In reply to Mark Millard from comment #11)

Hi Mark,

Thank you for explaining that for me, fuz@ has implemented the fix in bug #271987 too.
Comment 13 Mark Millard 2023-07-02 07:35:06 UTC
(In reply to Alastair Hogge from comment #12)

As I understand, emulators/qmc2 was changed such that it avoids
hitting the compiler crash. The compiler in use for the likes of
quarterly 131arm64 still has its original problem(s).
Comment 14 Alastair Hogge 2023-07-15 01:34:41 UTC
Whoops. Keep this open.