example.c SIGBUS on armv7 when compiled with clang
Test case:
FROM ubuntu:24.04
RUN apt-get update && apt-get -y install clang cmake git && apt-get clean
RUN git clone https://github.com/zlib-ng/zlib-ng
ENV CC=clang
RUN cd zlib-ng && mkdir build && cd build && cmake ..
RUN cd zlib-ng/build && cmake --build . --config Release
RUN zlib-ng/build/example
Copy to ./Dockerfile, then test with podman build --arch armhf . (or s/podman/docker/). You'll need to have QEMU user-mode emulation configured.
Tested with commit 787c7f62ac. The run succeeds on amd64, and on armhf building with GCC 13.3.0, but fails on armhf with clang 18.1.3:
STEP 5/7: RUN cd zlib-ng && mkdir build && cd build && cmake ..
-- Using CMake version 3.28.3
-- ZLIB_HEADER_VERSION: 1.3.1
-- ZLIBNG_HEADER_VERSION: 2.2.3
-- The C compiler identification is Clang 18.1.3
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Arch detected: 'armv7'
-- Basearch of 'armv7' has been detected as: 'arm'
-- Performing Test FNO_LTO_AVAILABLE
-- Performing Test FNO_LTO_AVAILABLE - Success
-- Looking for features.h
-- Looking for features.h - found
-- Performing Test HAVE_FLOATABI_SOFTFP
-- Performing Test HAVE_FLOATABI_SOFTFP - Failed
-- Performing Test HAVE_FLOATABI_HARD
-- Performing Test HAVE_FLOATABI_HARD - Success
-- ARM floating point arch: -mfloat-abi=hard
-- Looking for arm_acle.h
-- Looking for arm_acle.h - found
-- Looking for sys/auxv.h
-- Looking for sys/auxv.h - found
-- Looking for sys/sdt.h
-- Looking for sys/sdt.h - not found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for linux/auxvec.h
-- Looking for linux/auxvec.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - done
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for strerror
-- Looking for strerror - found
-- Looking for posix_memalign
-- Looking for posix_memalign - found
-- Looking for aligned_alloc
-- Looking for aligned_alloc - found
-- Performing Test HAVE_NO_INTERPOSITION
-- Performing Test HAVE_NO_INTERPOSITION - Success
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY_HIDDEN
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY_HIDDEN - Success
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY_INTERNAL
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY_INTERNAL - Success
-- Performing Test HAVE_ATTRIBUTE_ALIGNED
-- Performing Test HAVE_ATTRIBUTE_ALIGNED - Success
-- Performing Test HAVE_BUILTIN_ASSUME_ALIGNED
-- Performing Test HAVE_BUILTIN_ASSUME_ALIGNED - Success
-- Performing Test HAVE_BUILTIN_CTZ
-- Performing Test HAVE_BUILTIN_CTZ - Success
-- Performing Test HAVE_BUILTIN_CTZLL
-- Performing Test HAVE_BUILTIN_CTZLL - Success
-- Performing Test HAVE_PTRDIFF_T
-- Performing Test HAVE_PTRDIFF_T - Success
-- Performing Test ARM_AUXV_HAS_CRC32
-- Performing Test ARM_AUXV_HAS_CRC32 - Failed
-- Performing Test ARM_HWCAP_HAS_CRC32
-- Performing Test ARM_HWCAP_HAS_CRC32 - Success
-- Performing Test ARM_AUXV_HAS_NEON
-- Performing Test ARM_AUXV_HAS_NEON - Success
-- Performing Test HAVE_MARCH_ARMV8_CRC
-- Performing Test HAVE_MARCH_ARMV8_CRC - Success
-- Performing Test HAVE_ACLE_FLAG
-- Performing Test HAVE_ACLE_FLAG - Success
-- Performing Test NEON_AVAILABLE
-- Performing Test NEON_AVAILABLE - Success
-- Performing Test NEON_HAS_LD4
-- Performing Test NEON_HAS_LD4 - Success
-- Performing Test HAVE_MARCH_ARMV6
-- Performing Test HAVE_MARCH_ARMV6 - Success
-- Performing Test HAVE_ARMV6_INLINE_ASM
-- Performing Test HAVE_ARMV6_INLINE_ASM - Success
-- Performing Test HAVE_ARMV6_INTRIN
-- Performing Test HAVE_ARMV6_INTRIN - Success
-- Architecture-specific source files: arch/arm/arm_features.c;arch/arm/crc32_acle.c;arch/arm/adler32_neon.c;arch/arm/chunkset_neon.c;arch/arm/compare256_neon.c;arch/arm/slide_hash_neon.c;arch/arm/slide_hash_armv6.c
-- The CXX compiler identification is Clang 18.1.3
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
-- Git checking out GoogleTest release-1.12.1
-- Found Python: /usr/bin/python3 (found version "3.12.3") found components: Interpreter
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- The following features have been enabled:
* CMAKE_BUILD_TYPE, Build type: Release (default)
* ACLE_CRC, Support ACLE optimized CRC hash generation, using "-march=armv8-a+crc"
* NEON_ADLER32, Support NEON instructions in adler32, using "-mfpu=neon"
* NEON_SLIDEHASH, Support NEON instructions in slide_hash, using "-mfpu=neon"
* ARMV6, Support ARMv6 SIMD instructions in slide_hash, using "-march=armv6"
* WITH_GZFILEOP, Compile with support for gzFile related functions
* ZLIB_ENABLE_TESTS, Build test binaries
* ZLIBNG_ENABLE_TESTS, Test zlib-ng specific API
* WITH_SANITIZER, Enable sanitizer support
* WITH_GTEST, Build gtest_zlib
* WITH_OPTIM, Build with optimisation
* WITH_NEW_STRATEGIES, Use new strategies
* WITH_RUNTIME_CPU_DETECTION, Build with runtime CPU detection
* WITH_ACLE, Build with ACLE
* WITH_NEON, Build with NEON intrinsics
* WITH_ARMV6, Build with ARMv6 SIMD
-- The following OPTIONAL packages have been found:
* Git
* Python
* Threads
-- The following features have been disabled:
* ZLIB_SYMBOL_PREFIX, Publicly exported symbols DO NOT have a custom prefix
* ZLIB_COMPAT, Compile with zlib compatible API
* WITH_FUZZERS, Build test/fuzz
* WITH_BENCHMARKS, Build test/benchmarks
* WITH_BENCHMARK_APPS, Build application benchmarks
* WITH_NATIVE_INSTRUCTIONS, Instruct the compiler to use the full instruction set on this host (gcc/clang -march=native)
* WITH_MAINTAINER_WARNINGS, Build with project maintainer warnings
* WITH_CODE_COVERAGE, Enable code coverage reporting
* WITH_INFLATE_STRICT, Build with strict inflate distance checking
* WITH_INFLATE_ALLOW_INVALID_DIST, Build with zero fill for inflate invalid distances
* INSTALL_UTILS, Copy minigzip and minideflate during install
-- The following OPTIONAL packages have not been found:
* GTest
-- Configuring done (200.4s)
-- Generating done (0.6s)
-- Build files have been written to: /zlib-ng/build
--> 20695311f858
STEP 6/7: RUN cd zlib-ng/build && cmake --build . --config Release
[...]
--> bd376b50492e
STEP 7/7: RUN zlib-ng/build/example
qemu: uncaught target signal 7 (Bus error) - core dumped
Bus error (core dumped)
Error: building at STEP "RUN zlib-ng/build/example": while running runtime: exit status 135
podman evidently swallows the output from ./example; it is:
zlib-ng version 2.2.3 = 0x020203f0, compile flags = 0x55
uncompress(): hello, hello!
gzread(): hello, hello!
gzgets() after gzseek: hello!
gzgets(): hello, hello!
inflate(): hello, hello!
qemu: uncaught target signal 7 (Bus error) - core dumped
Bus error (core dumped)
Here's some GDB output:
0xb6f709c8 in NEON_accum32 (s=0xbefff634, buf=0xb6f3d030 "hello, hello!", len=347) at ../subprojects/zlib-ng-2.2.3/arch/arm/adler32_neon.c:46
46 uint8x16x4_t d0_d3 = vld1q_u8_x4(buf);
(gdb) bt
#0 0xb6f709c8 in NEON_accum32 (s=0xbefff634, buf=0xb6f3d030 "hello, hello!", len=347) at ../subprojects/zlib-ng-2.2.3/arch/arm/adler32_neon.c:46
#1 0xb6f70434 in adler32_neon (adler=1, buf=0xb6f3d030 "hello, hello!", len=40000) at ../subprojects/zlib-ng-2.2.3/arch/arm/adler32_neon.c:196
#2 0xb6f53100 in adler32_fold_copy_c (adler=1, dst=0xb6ee7100 "", src=0xb6f3d030 "hello, hello!", len=40000)
at ../subprojects/zlib-ng-2.2.3/arch/generic/adler32_fold_c.c:12
#3 0xb6f5a4a8 in zng_read_buf (strm=0xbefff774, buf=0xb6ee7100 "", size=65536) at ../subprojects/zlib-ng-2.2.3/deflate.c:1204
#4 0xb6f57ba0 in zng_fill_window (s=0xb6f3b100) at ../subprojects/zlib-ng-2.2.3/deflate.c:1316
#5 0xb6f5ca98 in deflate_quick (s=0xb6f3b100, flush=0) at ../subprojects/zlib-ng-2.2.3/deflate_quick.c:74
#6 0xb6f5970c in zng_deflate (strm=0xbefff774, flush=0) at ../subprojects/zlib-ng-2.2.3/deflate.c:1043
#7 0x004024d8 in test_large_deflate (compr=0xb6f47020 "x\001\313H\315\311\311\327", <incomplete sequence \310>, comprLen=40000,
uncompr=0xb6f3d030 "hello, hello!", uncomprLen=40000, zng_params=0) at ../subprojects/zlib-ng-2.2.3/test/example.c:291
#8 0x00401554 in main (argc=1, argv=0xbefff844) at ../subprojects/zlib-ng-2.2.3/test/example.c:973
This is with clang-17 and musl (Alpine Linux).
I can't say I can make much of the error.
edit: and some output from clang-11 on debian:
[4/45] Compiling C object subprojects/zlib-ng-2.2.3/libneon.a.p/arch_arm_adler32_neon.c.o
FAILED: subprojects/zlib-ng-2.2.3/libneon.a.p/arch_arm_adler32_neon.c.o
clang -Isubprojects/zlib-ng-2.2.3/libneon.a.p -Isubprojects/zlib-ng-2.2.3 -I../subprojects/zlib-ng-2.2.3 -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c11 -O0 -g -fPIC -D_LARGEFILE64_SOURCE=1 -D__USE_LARGEFILE64 -DHAVE_LINUX_AUXVEC_H -DHAVE_SYS_AUXV_H -DHAVE_ARM_ACLE_H -DHAVE_BUILTIN_ASSUME_ALIGNED -DHAVE_BUILTIN_CTZ -DHAVE_BUILTIN_CTZLL -DHAVE_ALIGNED_ALLOC -DHAVE_POSIX_MEMALIGN -DHAVE_ATTRIBUTE_ALIGNED -DHAVE_VISIBILITY_HIDDEN -DHAVE_VISIBILITY_INTERNAL -DWITH_GZFILEOP -DARM_FEATURES -DARM_AUXV_HAS_CRC32 -DARM_ASM_HWCAP -DARM_AUXV_HAS_NEON -DARM_ACLE -DARM_NEON -DARM_NEON_HASLD4 -mfpu=neon -MD -MQ subprojects/zlib-ng-2.2.3/libneon.a.p/arch_arm_adler32_neon.c.o -MF subprojects/zlib-ng-2.2.3/libneon.a.p/arch_arm_adler32_neon.c.o.d -o subprojects/zlib-ng-2.2.3/libneon.a.p/arch_arm_adler32_neon.c.o -c ../subprojects/zlib-ng-2.2.3/arch/arm/adler32_neon.c
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: clang -Isubprojects/zlib-ng-2.2.3/libneon.a.p -Isubprojects/zlib-ng-2.2.3 -I../subprojects/zlib-ng-2.2.3 -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c11 -O0 -g -fPIC -D_LARGEFILE64_SOURCE=1 -D__USE_LARGEFILE64 -DHAVE_LINUX_AUXVEC_H -DHAVE_SYS_AUXV_H -DHAVE_ARM_ACLE_H -DHAVE_BUILTIN_ASSUME_ALIGNED -DHAVE_BUILTIN_CTZ -DHAVE_BUILTIN_CTZLL -DHAVE_ALIGNED_ALLOC -DHAVE_POSIX_MEMALIGN -DHAVE_ATTRIBUTE_ALIGNED -DHAVE_VISIBILITY_HIDDEN -DHAVE_VISIBILITY_INTERNAL -DWITH_GZFILEOP -DARM_FEATURES -DARM_AUXV_HAS_CRC32 -DARM_ASM_HWCAP -DARM_AUXV_HAS_NEON -DARM_ACLE -DARM_NEON -DARM_NEON_HASLD4 -mfpu=neon -MD -MQ subprojects/zlib-ng-2.2.3/libneon.a.p/arch_arm_adler32_neon.c.o -MF subprojects/zlib-ng-2.2.3/libneon.a.p/arch_arm_adler32_neon.c.o.d -o subprojects/zlib-ng-2.2.3/libneon.a.p/arch_arm_adler32_neon.c.o -c ../subprojects/zlib-ng-2.2.3/arch/arm/adler32_neon.c
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module '../subprojects/zlib-ng-2.2.3/arch/arm/adler32_neon.c'.
4. Running pass 'ARM Instruction Selection' on function '@NEON_accum32'
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Debian clang version 11.0.1-2
Target: armv7l-unknown-linux-gnueabihf
Thread model: posix
InstalledDir: /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: /tmp/adler32_neon-ff0088.c
clang: note: diagnostic msg: /tmp/adler32_neon-ff0088.sh
clang: note: diagnostic msg:
it seems LLVM hates NEON_accum32 for some reason
Found the problem: https://github.com/zlib-ng/zlib-ng/blob/develop/arch/arm/neon_intrins.h#L28
remove ANDROID.
Ah yeah, looks like that's https://github.com/zlib-ng/zlib-ng/pull/1824.
Ok, so the compiler crashing here is probably a compiler bug (and a very strange one). This should maybe be filed upstream.
No reason to. It happens with clang 11 but not future versions like 17. It got fixed at some point.