simd-everywhere / simde

Implementations of SIMD instruction sets for systems which don't natively support them.
https://simd-everywhere.github.io/blog/
MIT License
2.38k stars 247 forks source link

arm/neon/crc32.h:59:12: error: always_inline function '__crc32b' requires target feature 'crc' when building 0.8.2 with clang on aarch64 #1200

Closed rathann closed 1 month ago

rathann commented 3 months ago

When building simde-0.8.2 with clang-18.1.8 on Fedora rawhide on aarch64, I'm getting the following error:

...
== Tests on clang with flags used in RPM package build ==
+ '[' include = include ']'
+ result=ok
+ result_buf=ok
+ return 0
+ result_gcc_rpm=ok
+ echo '== Tests on clang with flags used in RPM package build =='
+ BUILD_DIR=build/clang-rpm
+ CC=clang
+ CXX=clang++
+ CFLAGS='-O2 -flto=thin -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-
D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS --config=/usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong   -mbranch-prot
ection=standard -fasynchronous-unwind-tables  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer  -fno-strict-aliasing'
+ CXXFLAGS='-O2 -flto=thin -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE
,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS --config=/usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong   -mbranch-pr
otection=standard -fasynchronous-unwind-tables  -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer  -fno-strict-aliasing'
+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,pack-relative-relocs -Wl,-z,now --config=/usr/lib/rpm/redhat/redhat-hardened-clang-ld.cfg  -
flto=thin -ffat-lto-objects -Wl,--build-id=sha1  '
+ _run_test_and_get_result include
+ local exit_status=0
+ local result=skipped
+ '[' 1 -lt 1 ']'
+ local cond=include
+ '[' include = include ']'
+ _run_test
+ _setup
+ meson setup build/clang-rpm
The Meson build system
Version: 1.4.1
Source dir: /builddir/build/BUILD/simde-0.8.2-build/simde-0.8.2
Build dir: /builddir/build/BUILD/simde-0.8.2-build/simde-0.8.2/build/clang-rpm
Build type: native build
Project name: SIMDe
Project version: 0.8.2
C compiler for the host machine: clang (clang 18.1.8 "clang version 18.1.8 (Fedora 18.1.8-3.fc41)")
C linker for the host machine: clang ld.bfd 2.42.90.20240720
C++ compiler for the host machine: clang++ (clang 18.1.8 "clang version 18.1.8 (Fedora 18.1.8-3.fc41)")
C++ linker for the host machine: clang++ ld.bfd 2.42.90.20240720
Host machine cpu family: aarch64
Host machine cpu: aarch64
Library m found: YES
Compiler for C supports arguments -fopenmp-simd: YES 
Compiler for C++ supports arguments -fopenmp-simd: YES 
Compiler for C supports arguments -Wpsabi: YES 
Compiler for C++ supports arguments -Wpsabi: YES 
Library m found: YES
Found pkg-config: YES (/usr/bin/pkg-config) 2.1.1
Build targets in project: 2002
NOTICE: Future-deprecated features used:
 * 0.64.0: {'copy arg in configure_file'}
Found ninja-1.12.1 at /usr/bin/ninja
+ _build
+ rm -f build.log
+ _time ninja -C build/clang-rpm -v -j 4
+ cat build.log
+ /bin/time -f '=> [%E]' ninja -C build/clang-rpm -v -j 4
ninja: Entering directory `build/clang-rpm'
[1/4004] clang -Itest/common/common-c.p -Itest/common -I../../test/common -I. -I../.. -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c99 -O0 -g -O2 -flto=thin -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS --config=/usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong -mbranch-protection=standard -fasynchronous-unwind-tables -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-aliasing -fopenmp-simd -DSIMDE_CONSTRAINED_COMPILATION -DSIMDE_ENABLE_OPENMP -Wno-psabi -DSIMDE_TEST_BARE -MD -MQ test/common/common-c.p/common.c.o -MF test/common/common-c.p/common.c.o.d -o test/common/common-c.p/common.c.o -c ../../test/common/common.c
...
[750/4004] clang -Itest/arm/neon/crc32-native-c.p -Itest/arm/neon -I../../test/arm/neon -I. -I../.. -fdiagnostics-color=always -D_FILE_OFFSE
T_BITS=64 -Wall -Winvalid-pch -std=c99 -O0 -g -O2 -flto=thin -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=for
mat-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS --config=/usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fst
ack-protector-strong -mbranch-protection=standard -fasynchronous-unwind-tables -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-str
ict-aliasing -fopenmp-simd -DSIMDE_CONSTRAINED_COMPILATION -DSIMDE_ENABLE_OPENMP -Wno-psabi -DSIMDE_TEST_BARE -MD -MQ test/arm/neon/crc32-na
tive-c.p/crc32.c.o -MF test/arm/neon/crc32-native-c.p/crc32.c.o.d -o test/arm/neon/crc32-native-c.p/crc32.c.o -c ../../test/arm/neon/crc32.c
FAILED: test/arm/neon/crc32-native-c.p/crc32.c.o 
clang -Itest/arm/neon/crc32-native-c.p -Itest/arm/neon -I../../test/arm/neon -I. -I../.. -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -
Wall -Winvalid-pch -std=c99 -O0 -g -O2 -flto=thin -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-securit
y -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS --config=/usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protect
or-strong -mbranch-protection=standard -fasynchronous-unwind-tables -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-aliasin
g -fopenmp-simd -DSIMDE_CONSTRAINED_COMPILATION -DSIMDE_ENABLE_OPENMP -Wno-psabi -DSIMDE_TEST_BARE -MD -MQ test/arm/neon/crc32-native-c.p/cr
c32.c.o -MF test/arm/neon/crc32-native-c.p/crc32.c.o.d -o test/arm/neon/crc32-native-c.p/crc32.c.o -c ../../test/arm/neon/crc32.c
In file included from ../../test/arm/neon/crc32.c:4:
../../test/arm/neon/../../../simde/arm/neon/crc32.h:59:12: error: always_inline function '__crc32b' requires target feature 'crc', but would
 be inlined into function 'simde___crc32b' that is compiled without support for 'crc'
   59 |     return __crc32b(a, b);
      |            ^
../../test/arm/neon/../../../simde/arm/neon/crc32.h:85:12: error: always_inline function '__crc32h' requires target feature 'crc', but would
 be inlined into function 'simde___crc32h' that is compiled without support for 'crc'
   85 |     return __crc32h(a, b);
      |            ^
../../test/arm/neon/../../../simde/arm/neon/crc32.h:111:12: error: always_inline function '__crc32w' requires target feature 'crc', but woul
d be inlined into function 'simde___crc32w' that is compiled without support for 'crc'
  111 |     return __crc32w(a, b);
      |            ^
../../test/arm/neon/../../../simde/arm/neon/crc32.h:136:12: error: always_inline function '__crc32d' requires target feature 'crc', but would be inlined into function 'simde___crc32d' that is compiled without support for 'crc'
  136 |     return __crc32d(a, b);
      |            ^
../../test/arm/neon/../../../simde/arm/neon/crc32.h:171:12: error: always_inline function '__crc32cb' requires target feature 'crc', but would be inlined into function 'simde___crc32cb' that is compiled without support for 'crc'
  171 |     return __crc32cb(a, b);
      |            ^
../../test/arm/neon/../../../simde/arm/neon/crc32.h:197:12: error: always_inline function '__crc32ch' requires target feature 'crc', but would be inlined into function 'simde___crc32ch' that is compiled without support for 'crc'
  197 |     return __crc32ch(a, b);
      |            ^
../../test/arm/neon/../../../simde/arm/neon/crc32.h:223:12: error: always_inline function '__crc32cw' requires target feature 'crc', but would be inlined into function 'simde___crc32cw' that is compiled without support for 'crc'
  223 |     return __crc32cw(a, b);
      |            ^
../../test/arm/neon/../../../simde/arm/neon/crc32.h:248:12: error: always_inline function '__crc32cd' requires target feature 'crc', but would be inlined into function 'simde___crc32cd' that is compiled without support for 'crc'
  248 |     return __crc32cd(a, b);
      |            ^
8 errors generated.
...
ninja: build stopped: subcommand failed.
Command exited with non-zero status 1
=> [3:47.29]
== Results ==
Exit status: 1
skipped: gcc without flags
skipped: gcc with -O2 flag
ok: gcc with RPM build flags
skipped: clang without flags
skipped: clang with -O2 flag
not ok: clang with RPM build flags
rathann commented 2 months ago

meson has no support for file-specific compiler flags, but this patch seems to work around the issue for me (all 2002 tests succeed):

diff -up simde-0.8.2/test/meson.build.orig simde-0.8.2/test/meson.build
--- simde-0.8.2/test/meson.build.orig   2024-04-30 16:35:50.000000000 +0000
+++ simde-0.8.2/test/meson.build        2024-08-30 11:22:14.428728668 +0000
@@ -58,6 +58,10 @@ if cxx.get_id() == 'intel'
   simde_native_cxx_flags += '-DSIMDE_FAST_MATH'
 endif

+if target_machine.cpu_family() == 'aarch64' and cc.get_id() == 'clang'
+  simde_native_c_flags += '-mcrc'
+endif
+
 if not c_openmp_simd
   simde_deps += dependency('openmp', required: false)
 endif
mr-c commented 1 month ago

Hello @rathann and thank you for sharing your issue.

Not all aarch64 CPUs have the crc32 feature, so we shouldn't enable it universally.

I will open a PR that avoids using the crc32 feature unless it is already enabled.

Alas, it looks like -march=native doesn't enable crc32 automatically on many processors. You may need to use -march=armv8-a+crc or similar

See https://stackoverflow.com/questions/45625725/does-clang-lack-crc32-for-armv8-aarch64 and https://stackoverflow.com/questions/37066261/why-is-arm-feature-crc32-not-being-defined-by-the-compiler

rathann commented 1 month ago

Hello @rathann and thank you for sharing your issue.

Hi! You're welcome! I'm always happy to work with upstreams on the issues we catch downstream in Fedora.

Not all aarch64 CPUs have the crc32 feature, so we shouldn't enable it universally.

I see.

I will open a PR that avoids using the crc32 feature unless it is already enabled.

Great, thanks! I'll test it as soon as I can.

Alas, it looks like -march=native doesn't enable crc32 automatically on many processors. You may need to use -march=armv8-a+crc or similar

Interesting. Thanks for the links.