From: Bruno Haible Date: Sun, 22 Dec 2024 00:09:17 +0000 (+0100) Subject: crc-x86_64: Fix compilation error with clang in a simpler way. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc8428747220f9b08128a09d33ef1f241b12ae2a;p=thirdparty%2Fgnulib.git crc-x86_64: Fix compilation error with clang in a simpler way. Suggested by Collin Funk. * modules/crc-x86_64 (Makefile.am): Revert last change. * lib/crc-x86_64-pclmul.c: Normalize includes. (crc32_update_no_xor_pclmul): Use __attribute__ ((__target (...))). * m4/crc-x86_64.m4 (gl_CRC_X86_64_PCLMUL): Use __attribute__ ((__target (...))) here as well. Don't use modified CFLAGS. --- diff --git a/ChangeLog b/ChangeLog index 70dfe4f0a7..4121ec0018 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2024-12-21 Bruno Haible + crc-x86_64: Fix compilation error with clang in a simpler way. + Suggested by Collin Funk. + * modules/crc-x86_64 (Makefile.am): Revert last change. + * lib/crc-x86_64-pclmul.c: Normalize includes. + (crc32_update_no_xor_pclmul): Use __attribute__ ((__target (...))). + * m4/crc-x86_64.m4 (gl_CRC_X86_64_PCLMUL): Use + __attribute__ ((__target (...))) here as well. Don't use modified + CFLAGS. + crc-x86_64: Fix compilation error with clang. * modules/crc-x86_64 (Makefile.am): Declare a separate library libpclmul.{a,la}. diff --git a/lib/crc-x86_64-pclmul.c b/lib/crc-x86_64-pclmul.c index 91f361d2ce..170ebfcef0 100644 --- a/lib/crc-x86_64-pclmul.c +++ b/lib/crc-x86_64-pclmul.c @@ -18,12 +18,17 @@ #include +/* Specification. */ #include "crc-x86_64.h" -#include "x86intrin.h" -#include "crc.h" #include +#include + +#include "crc.h" +#if defined __GNUC__ || defined __clang__ +__attribute__ ((__target__ ("pclmul,avx"))) +#endif uint32_t crc32_update_no_xor_pclmul (uint32_t crc, const void *buf, size_t len) { diff --git a/m4/crc-x86_64.m4 b/m4/crc-x86_64.m4 index fa649a5b82..470e6333ff 100644 --- a/m4/crc-x86_64.m4 +++ b/m4/crc-x86_64.m4 @@ -1,5 +1,5 @@ # crc-x86_64.m4 -# serial 2 +# serial 3 dnl Copyright (C) 2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,14 +8,15 @@ dnl This file is offered as-is, without any warranty. AC_DEFUN([gl_CRC_X86_64_PCLMUL], [ - ac_save_CFLAGS=$CFLAGS - CFLAGS="-mavx -mpclmul $CFLAGS" AC_CACHE_CHECK([if pclmul intrinsic exists], [gl_cv_crc_pclmul], [ AC_LINK_IFELSE( [AC_LANG_SOURCE( [[ #include + #if defined __GNUC__ || defined __clang__ + __attribute__ ((__target__ ("pclmul,avx"))) + #endif int main (void) { @@ -37,5 +38,4 @@ AC_DEFUN([gl_CRC_X86_64_PCLMUL], fi AM_CONDITIONAL([GL_CRC_X86_64_PCLMUL], [test $gl_cv_crc_pclmul = yes]) - CFLAGS=$ac_save_CFLAGS ]) diff --git a/modules/crc-x86_64 b/modules/crc-x86_64 index 15876991ab..2e4b5bf744 100644 --- a/modules/crc-x86_64 +++ b/modules/crc-x86_64 @@ -15,17 +15,7 @@ AC_REQUIRE([gl_CRC_X86_64_PCLMUL]) Makefile.am: if GL_CRC_X86_64_PCLMUL -# We need a separate library, in order to compile crc-x86_64-pclmul.c with -# particular CFLAGS. -# (Recall that '#pragma GCC target (...)' works only with gcc, not with clang. -# And the alternative approach of target-specific CFLAGS in 'make' syntax -# -# is not portable: it does not work with OpenBSD 'make'.) -noinst_@LT@LIBRARIES += libpclmul.@la@ -libpclmul_@la@_SOURCES = crc-x86_64-pclmul.c -libpclmul_@la@_CFLAGS = $(AM_CFLAGS) -mavx -mpclmul -lib_LIBADD += libpclmul_@la@-crc-x86_64-pclmul.@lo@ -lib_DEPENDENCIES += libpclmul.@la@ +lib_SOURCES += crc-x86_64-pclmul.c endif Include: