this is a shame, the pragma option seemed super clean if clang worked with it. ad hoc library seems like a close second given we can't change CFLAGS without changing the whole repo
On Sat, Dec 21, 2024, 23:14 Bruno Haible <br...@clisp.org> wrote: > The gnulib CIs also exercise compilation with clang, and it failed today: > > clang -DHAVE_CONFIG_H -I. -I../../gllib -I.. -DGNULIB_STRICT_CHECKING=1 > -I/media/develdata/devel/inst-x86_64-64/include -Wall -g -O2 -MT > crc-x86_64-pclmul.o -MD -MP -MF .deps/crc-x86_64-pclmul.Tpo -c -o > crc-x86_64-pclmul.o ../../gllib/crc-x86_64-pclmul.c > ../../gllib/crc-x86_64-pclmul.c:27:13: warning: unknown pragma ignored > [-Wunknown-pragmas] > #pragma GCC push_options > ^ > ../../gllib/crc-x86_64-pclmul.c:28:13: warning: unknown pragma ignored > [-Wunknown-pragmas] > #pragma GCC target("pclmul,avx") > ^ > ../../gllib/crc-x86_64-pclmul.c:208:13: warning: unknown pragma ignored > [-Wunknown-pragmas] > #pragma GCC pop_options > ^ > ../../gllib/crc-x86_64-pclmul.c:83:16: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_high = _mm_clmulepi64_si128 (in1, shift544_shift480, 0x11); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:84:15: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_low = _mm_clmulepi64_si128 (in1, shift544_shift480, 0x00); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:87:16: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_high = _mm_clmulepi64_si128 (in2, shift544_shift480, 0x11); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:88:15: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_low = _mm_clmulepi64_si128 (in2, shift544_shift480, 0x00); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:91:16: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_high = _mm_clmulepi64_si128 (in3, shift544_shift480, 0x11); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:92:15: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_low = _mm_clmulepi64_si128 (in3, shift544_shift480, 0x00); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:95:16: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_high = _mm_clmulepi64_si128 (in4, shift544_shift480, 0x11); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:96:15: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_low = _mm_clmulepi64_si128 (in4, shift544_shift480, 0x00); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:133:19: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_high = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x11); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:134:18: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_low = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x00); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:164:19: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_high = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x11); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:165:18: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > fold_low = _mm_clmulepi64_si128 (in1, shift160_shift96, 0x00); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:180:9: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > in1 = _mm_clmulepi64_si128 (shift96_shift64, in1, 0x00); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:187:9: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > in1 = _mm_clmulepi64_si128 (shift96_shift64, in2, 0x01); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:194:9: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > in2 = _mm_clmulepi64_si128 (mu_poly, in2, 0x00); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > ../../gllib/crc-x86_64-pclmul.c:198:9: error: > '__builtin_ia32_pclmulqdq128' needs target feature pclmul > in2 = _mm_clmulepi64_si128 (mu_poly, in2, 0x01); > ^ > /clang/14.0.0/include/__wmmintrin_pclmul.h:45:13: note: expanded from > macro '_mm_clmulepi64_si128' > ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(X), \ > ^ > 3 warnings and 16 errors generated. > make[3]: *** [Makefile:1123: crc-x86_64-pclmul.o] Error 1 > > > This is reproducible with clang versions 7 to 19 (the newest one), for > example > in a testdir: > > $ ./gnulib-tool --create-testdir --dir=../testdir1 --single-configure > crc crc-x86_64 > > The reason is that clang does not support the '#pragma GCC target(...)'. > > > Three approaches to fix this are possible: > > a) As suggested by Simon in > <https://lists.gnu.org/archive/html/bug-gnulib/2024-12/msg00112.html>: > Use the '#pragma GCC target(...)' also in configure.ac. > Drawback: This means to disable the optimization when clang is used to > build the package. > > b) Use the per-object flag syntax from > > https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html > : > > crc-x86_64-pclmul.o: CFLAGS += -mavx -mpclmul > > Drawback: This works with GNU make, FreeBSD make, NetBSD make, but not > with > OpenBSD make. > > c) Use an ad-hoc library in the Makefile. This is well supported in > Automake > and thus does not cause portability problems. > Drawback: It requires changes in gnulib-tool. > > I picked approach c), and committed the two attached patches. Tested both > without libtool (in a testdir) and with libtool (in some package that uses > gnulib for some shared library). > > > 2024-12-21 Bruno Haible <br...@clisp.org> > > crc-x86_64: Fix compilation error with clang. > * modules/crc-x86_64 (Makefile.am): Declare a separate library > libpclmul.{a,la}. > * lib/crc-x86_64-pclmul.c: Remove the GCC pragmas. > > gnulib-tool: Recognize @LT@, @la@, @lo@ tokens in module > descriptions. > * gnulib-tool.sh (func_emit_lib_Makefile_am): Replace @LT@, @la@, > @lo@ > tokens. > (func_emit_tests_Makefile_am): Likewise. > * pygnulib/GLEmiter.py (GLEmiter.lib_Makefile_am): Likewise. > (GLEmiter.tests_Makefile_am): Likewise. > >