ebiggers / libdeflate

Heavily optimized library for DEFLATE/zlib/gzip compression and decompression

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

arm_acle.h compiler errors when building for iOS with Xcode 15.3

geertbleyen opened this issue · comments

When building for iOS when using Xcode 15.3, several compile errors occur in arm_acle.h:

❯ cmake -G "Unix Makefiles" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_SYSTEM_NAME="iOS" -DCMAKE_SYSTEM_PROCESSOR="arm64" ../../src && make
-- The C compiler identification is AppleClang 15.0.0.15000309
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test HAVE_WDECLARATION_AFTER_STATEMENT
-- Performing Test HAVE_WDECLARATION_AFTER_STATEMENT - Success
-- Performing Test HAVE_WIMPLICIT_FALLTHROUGH
-- Performing Test HAVE_WIMPLICIT_FALLTHROUGH - Success
-- Performing Test HAVE_WMISSING_FIELD_INITIALIZERS
-- Performing Test HAVE_WMISSING_FIELD_INITIALIZERS - Success
-- Performing Test HAVE_WMISSING_PROTOTYPES
-- Performing Test HAVE_WMISSING_PROTOTYPES - Success
-- Performing Test HAVE_WPEDANTIC
-- Performing Test HAVE_WPEDANTIC - Success
-- Performing Test HAVE_WSHADOW
-- Performing Test HAVE_WSHADOW - Success
-- Performing Test HAVE_WSTRICT_PROTOTYPES
-- Performing Test HAVE_WSTRICT_PROTOTYPES - Success
-- Performing Test HAVE_WUNDEF
-- Performing Test HAVE_WUNDEF - Success
-- Performing Test HAVE_WVLA
-- Performing Test HAVE_WVLA - Success
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Looking for futimens
-- Looking for futimens - found
-- Looking for posix_fadvise
-- Looking for posix_fadvise - not found
-- Looking for posix_madvise
-- Looking for posix_madvise - found
-- Performing Test HAVE_STAT_NANOSECOND_PRECISION
-- Performing Test HAVE_STAT_NANOSECOND_PRECISION - Failed
-- Configuring done (2.6s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/geertbl/repos/libdeflate/build/Release
[  3%] Building C object CMakeFiles/libdeflate_static.dir/lib/arm/cpu_features.c.o
[  6%] Building C object CMakeFiles/libdeflate_static.dir/lib/utils.c.o
[ 10%] Building C object CMakeFiles/libdeflate_static.dir/lib/x86/cpu_features.c.o
[ 13%] Building C object CMakeFiles/libdeflate_static.dir/lib/deflate_compress.c.o
[ 17%] Building C object CMakeFiles/libdeflate_static.dir/lib/deflate_decompress.c.o
[ 20%] Building C object CMakeFiles/libdeflate_static.dir/lib/adler32.c.o
[ 24%] Building C object CMakeFiles/libdeflate_static.dir/lib/zlib_compress.c.o
[ 27%] Building C object CMakeFiles/libdeflate_static.dir/lib/zlib_decompress.c.o
[ 31%] Building C object CMakeFiles/libdeflate_static.dir/lib/crc32.c.o
In file included from /Users/geertbl/repos/libdeflate/src/lib/crc32.c:226:
In file included from /Users/geertbl/repos/libdeflate/src/lib/arm/crc32_impl.h:31:
In file included from /Users/geertbl/repos/libdeflate/src/lib/arm/cpu_features.h:248:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/arm_acle.h:595:10: error: '__builtin_arm_crc32b' needs target feature crc
  return __builtin_arm_crc32b(__a, __b);
         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/arm_acle.h:600:10: error: '__builtin_arm_crc32h' needs target feature crc
  return __builtin_arm_crc32h(__a, __b);
         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/arm_acle.h:605:10: error: '__builtin_arm_crc32w' needs target feature crc
  return __builtin_arm_crc32w(__a, __b);
         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/arm_acle.h:610:10: error: '__builtin_arm_crc32d' needs target feature crc
  return __builtin_arm_crc32d(__a, __b);
         ^
4 errors generated.
make[2]: *** [CMakeFiles/libdeflate_static.dir/lib/crc32.c.o] Error 1
make[1]: *** [CMakeFiles/libdeflate_static.dir/all] Error 2

Seems like somewhere the incorrect compiles features are set.
When building with Xcode 15.0.1, or omitting -DCMAKE_SYSTEM_NAME="iOS" from cmake command, the issue does not occur.

Any assistance is appreciated.

It looks like the problem is that for a couple weeks in the llvm-project development branch, arm64 crc intrinsics did not work unless crc support was enabled in the whole file, and Apple happened to fork LLVM during that time and release it starting sometime in the Xcode 15 series. (It's after llvm/llvm-project@b2d7a0d but before llvm/llvm-project@30b67c6.)

The "fix" is likely going to be to disable the use of crc instructions on those versions of Xcode, which will make it compile but will reduce CRC-32 performance. It may be a good idea to use a different version of Xcode so that your build of libdeflate can use these instructions. Note that this problem will go away in future versions of Xcode due to the incorporation of llvm/llvm-project@30b67c6, so it's likely just going to be a few versions in the 15.x series that will be affected.

Thanks for the detailed information! The projects where we need to do these compiles don't have a hard dependency on Xcode versions above 15.0.1, so we can stick with that version for now.

3b766cd fixed this by using a fallback to inline assembly. You should be able to use the latest Xcode now. I don't have a way to easily test different Xcode versions, so let me know if it still doesn't work for some reason. Thanks!

@ebiggers , I can confirm this issues has been solved in 3b766cd for Xcode 15.3 (I haven't tested 15.1. or 15.2).
Much appreciated!