shibatch / sleef

SIMD Library for Evaluating Elementary Functions, vectorized libm and DFT
https://sleef.org
Boost Software License 1.0
661 stars 131 forks source link

Segfault when building with Apple Clang 15 #474

Closed adamjstewart closed 8 months ago

adamjstewart commented 12 months ago

I'm seeing a segfault when building from the master branch:

[ 16%] Building C object src/libm/CMakeFiles/sleefsvenofma.dir/sleefsimdsp.c.o
cd /private/var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/Adam/spack-stage/spack-stage-sleef-master-bkjovz22gqqp45s2ymskxx4dcu6azr5y/spack-build-bkjovz2/src/libm && /Users/Adam/spack/lib/spack/env/clang/clang -DDORENAME=1 -DENABLE_BUILTIN_MATH=1 -DENABLE_SVENOFMA=1 -I/var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/Adam/spack-stage/spack-stage-sleef-master-bkjovz22gqqp45s2ymskxx4dcu6azr5y/spack-src/src/common -I/var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/Adam/spack-stage/spack-stage-sleef-master-bkjovz22gqqp45s2ymskxx4dcu6azr5y/spack-src/src/arch -I/private/var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/Adam/spack-stage/spack-stage-sleef-master-bkjovz22gqqp45s2ymskxx4dcu6azr5y/spack-build-bkjovz2/src/libm/include -I/var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/Adam/spack-stage/spack-stage-sleef-master-bkjovz22gqqp45s2ymskxx4dcu6azr5y/spack-src/src/libm -Wall -Wno-unused-function -Wno-attributes -Wno-unused-result -ffp-contract=off -fno-math-errno -fno-trapping-math -O3 -DNDEBUG -std=gnu99 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -mmacosx-version-min=14.0 -fPIC -march=armv8-a+sve -MD -MT src/libm/CMakeFiles/sleefsvenofma.dir/sleefsimdsp.c.o -MF CMakeFiles/sleefsvenofma.dir/sleefsimdsp.c.o.d -o CMakeFiles/sleefsvenofma.dir/sleefsimdsp.c.o -c /var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/Adam/spack-stage/spack-stage-sleef-master-bkjovz22gqqp45s2ymskxx4dcu6azr5y/spack-src/src/libm/sleefsimdsp.c
clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/sleefsimdsp-e26a4a.c
clang: note: diagnostic msg: /var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/sleefsimdsp-e26a4a.sh
clang: note: diagnostic msg: Crash backtrace is located in
clang: note: diagnostic msg: /Users/Adam/Library/Logs/DiagnosticReports/clang_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
clang: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang: note: diagnostic msg: 

********************
make[2]: *** [src/libm/CMakeFiles/sleefsvenofma.dir/build.make:84: src/libm/CMakeFiles/sleefsvenofma.dir/sleefsimdsp.c.o] Error 1
make[2]: Leaving directory '/private/var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/Adam/spack-stage/spack-stage-sleef-master-bkjovz22gqqp45s2ymskxx4dcu6azr5y/spack-build-bkjovz2'
make[1]: *** [CMakeFiles/Makefile2:609: src/libm/CMakeFiles/sleefsvenofma.dir/all] Error 2
make[1]: Leaving directory '/private/var/folders/jv/cgkfvslj6nq1l7cw0c8c_8gm0000gn/T/Adam/spack-stage/spack-stage-sleef-master-bkjovz22gqqp45s2ymskxx4dcu6azr5y/spack-build-bkjovz2'
make: *** [Makefile:149: all] Error 2

See the full build log: spack-build-out.txt

I'm on macOS Sonoma 14.0 (Apple M2 Pro, arm64) using Apple Clang 15.0.0.

blapie commented 12 months ago

Hello! Thanks for reporting this. I don't have access to an Apple M2 atm, but spack install sleef@master on x86 seems functional (with same OS and compiler version). Will let you know if I'm able to reproduce on M2.

In the meantime would you be able to provide crash backtrace (.crash)? Maybe a list of dependencies (full spack install log, with steps prior cmake)? What version of XCode are you using? Does updating help?

Here is the version I used

$> /usr/bin/xcodebuild -version
Xcode 15.0.1
Build version 15A507
adamjstewart commented 12 months ago

In the meantime would you be able to provide crash backtrace (.crash)?

Here are all files mentioned in the error message: clang-2023-10-31-131600.000.ips.txt clang-2023-10-31-131600.0002.ips.txt clang-2023-10-31-131600.0003.ips.txt clang-2023-10-31-131600.0004.ips.txt clang-2023-10-31-131600.ips.txt sleefsimdsp-5a4b1a.c.txt sleefsimdsp-5a4b1a.sh.txt

Maybe a list of dependencies (full spack install log, with steps prior cmake)?

> spack spec sleef@master
Input spec
--------------------------------
 -   sleef@master

Concretized
--------------------------------
 -   sleef@master%apple-clang@15.0.0~ipo build_system=cmake build_type=Release generator=ninja arch=darwin-sonoma-m2
[+]      ^cmake@3.27.6%apple-clang@15.0.0~doc+ncurses+ownlibs build_system=generic build_type=Release arch=darwin-sonoma-m2
[+]          ^curl@8.1.2%apple-clang@15.0.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2+nghttp2 build_system=autotools libs=shared,static tls=secure_transport arch=darwin-sonoma-m2
[+]              ^gnuconfig@2022-09-17%apple-clang@15.0.0 build_system=generic arch=darwin-sonoma-m2
[+]              ^nghttp2@1.52.0%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m2
[+]              ^pkgconf@1.9.5%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m2
[+]          ^ncurses@6.4%apple-clang@15.0.0~symlinks+termlib abi=none build_system=autotools arch=darwin-sonoma-m2
[+]          ^zlib-ng@2.1.3%apple-clang@15.0.0+compat+opt build_system=autotools patches=299b958,86c3f5b,ae9077a,b692621 arch=darwin-sonoma-m2
[+]      ^ninja@1.11.1%apple-clang@15.0.0+re2c build_system=generic arch=darwin-sonoma-m2
[-]          ^python@3.11.4%apple-clang@15.0.0+bz2+crypt+ctypes+dbm~debug+libxml2+lzma~nis+optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tkinter+uuid+zlib build_system=generic patches=13fa8bf,b0615b2,ebdca64,f2fd060 arch=darwin-sonoma-m2
[e]              ^apple-libuuid@1353.100.2%apple-clang@15.0.0 build_system=bundle arch=darwin-sonoma-m2
[+]              ^bzip2@1.0.8%apple-clang@15.0.0~debug~pic+shared build_system=generic arch=darwin-sonoma-m2
[+]                  ^diffutils@3.9%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m2
[+]              ^expat@2.5.0%apple-clang@15.0.0~libbsd build_system=autotools arch=darwin-sonoma-m2
[+]              ^gdbm@1.23%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m2
[-]              ^gettext@0.21.1%apple-clang@15.0.0+bzip2+curses+git~libunistring+libxml2+tar+xz build_system=autotools arch=darwin-sonoma-m2
[+]                  ^libiconv@1.17%apple-clang@15.0.0 build_system=autotools libs=shared,static arch=darwin-sonoma-m2
[+]                  ^libxml2@2.10.3%apple-clang@15.0.0+pic~python+shared build_system=autotools arch=darwin-sonoma-m2
[+]                  ^tar@1.34%apple-clang@15.0.0 build_system=autotools zip=pigz arch=darwin-sonoma-m2
[+]                      ^pigz@2.7%apple-clang@15.0.0 build_system=makefile arch=darwin-sonoma-m2
[+]                      ^zstd@1.5.5%apple-clang@15.0.0+programs build_system=makefile compression=none libs=shared,static arch=darwin-sonoma-m2
[+]              ^libffi@3.4.4%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m2
[+]              ^libxcrypt@4.4.35%apple-clang@15.0.0~obsolete_api build_system=autotools patches=4885da3 arch=darwin-sonoma-m2
[+]                  ^perl@5.38.0%apple-clang@15.0.0+cpanm+opcode+open+shared+threads build_system=generic patches=714e4d1 arch=darwin-sonoma-m2
[+]                      ^berkeley-db@18.1.40%apple-clang@15.0.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=darwin-sonoma-m2
[+]              ^openssl@3.1.3%apple-clang@15.0.0~docs+shared build_system=generic certs=mozilla arch=darwin-sonoma-m2
[+]                  ^ca-certificates-mozilla@2023-05-30%apple-clang@15.0.0 build_system=generic arch=darwin-sonoma-m2
[+]              ^readline@8.2%apple-clang@15.0.0 build_system=autotools patches=bbf97f1 arch=darwin-sonoma-m2
[+]              ^sqlite@3.42.0%apple-clang@15.0.0+column_metadata+dynamic_extensions+fts~functions+rtree build_system=autotools arch=darwin-sonoma-m2
[+]              ^xz@5.4.1%apple-clang@15.0.0~pic build_system=autotools libs=shared,static arch=darwin-sonoma-m2
[+]          ^re2c@2.2%apple-clang@15.0.0 build_system=generic arch=darwin-sonoma-m2

What version of XCode are you using?

> /usr/bin/xcodebuild -version
Xcode 15.0.1
Build version 15A507

Does updating help?

Already up-to-date.

blapie commented 12 months ago

Thanks! There seems to be quite a few bugs flagged on Sonoma lately, so since this looks like a compiler error I would recommend filing a report to Apple Clang directly (as suggested by the error message). You will increase your chances to get a fix soon. In the meantime we will try to reproduce and maybe find a workaround.

adamjstewart commented 12 months ago

Filed a report.

adamjstewart commented 9 months ago

Finally got a reply from Apple 3 months later:

We’ve seen this issue with sleef before. The problem is you're trying to build with SVE on Darwin, which isn’t supported. Even if you could successfully build it, it won’t run because no Mac has SVE hardware.

Is there a CMake flag to disable SVE?

blapie commented 8 months ago

Hello! Sorry for the late reply. You might have found your answer already but yes there is a flag to disable SVE, simply pass -DSLEEF_DISABLE_SVE=ON to cmake. We can try to integrate that to the build system.

adamjstewart commented 8 months ago

Thanks, this worked great to build the master branch.

Unfortunately it doesn't work to build e0a003ee838b75d11763aa9c3ef17bf71a725bff, which is the version used by PyTorch. Maybe this flag didn't exist at the time? Was there a different flag available?

adamjstewart commented 8 months ago

Ah, looks like it was previously called DISABLE_SVE, let me try that.

adamjstewart commented 8 months ago

Yes, this worked great! I'll keep this issue open until your CMake configuration is able to auto-detect whether or not SVE is supported.

blapie commented 8 months ago

Cheers! Will try to sort that out ASAP.

blapie commented 8 months ago

Merged #512. Let me know if this is good for you, and please close issue! Cheers for the precious help on this!

adamjstewart commented 8 months ago

Confirmed that the build works out of the box now (barring my other issues #458 and #475). Thanks for the fix!