(Was: Re: [PATCH] wc: Add AVX2 optimization when counting only lines)

So, it looks like the check for avx2 support is broken - the build broke for me after the update. Seems it is doing a compile check when a link check is necessary.

I was seeing this in my build:

    src/wc.c: In function 'avx2_supported':
    src/wc.c:153:13: warning: implicit declaration of function 
'__get_cpuid_count' [-Wimplicit-function-declaration]
           if (! __get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
                 ^

    ...

    src/wc.o: In function `avx2_supported':
    /.../coreutils/src/wc.c:153: undefined reference to `__get_cpuid_count'
    collect2: error: ld returned 1 exit status
    Makefile:9415: recipe for target 'src/wc' failed


My config.h has:

    #define USE_AVX2_WC_LINECOUNT 1


My config.log has:

    configure:77113: checking if __get_cpuid_count exists
    configure:77129: gcc -c -g -O2  conftest.c >&5
    conftest.c: In function 'main':
    conftest.c:842:7: warning: implicit declaration of function 
'__get_cpuid_count' [-Wimplicit-function-declaration]
           __get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
           ^
    configure:77129: $? = 0
    configure:77131: result: yes


... So it looks like '__get_cpuid_count' not being declared is just treated as a warning, and so the compile test succeeds. The actual failure happens at link time. Would it be more appropriate to use AC_LINK_IFELSE instead of AC_COMPILE_IFELSE ?

I tried swapping this out (as in the attached patch), and now it correctly omits the #define for USE_AVX2_WC_LINECOUNT, and wc compiles & links properly.


Thanks,
Carl
From 4f7e27ae1745331772a835564f868e25ecae070c Mon Sep 17 00:00:00 2001
From: Carl Edquist <edqu...@cs.wisc.edu>
Date: Mon, 10 May 2021 05:22:11 -0500
Subject: [PATCH] configure.ac: fix __get_cpuid_count check to catch link
 failure

The test program will compile successfully even if __get_cpuid_count
is not declared.  The error for the missing symbol will only show up
at link time.  Thus, use AC_LINK_IFELSE instead of AC_COMPILE_IFELSE.

* configure.ac: (__get_cpuid_count check) use C_LINK_IFELSE instead
of AC_COMPILE_IFELSE.
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index f0fbbd9..f826a4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -576,7 +576,7 @@ AM_CONDITIONAL([USE_PCLMUL_CRC32],
 CFLAGS=$ac_save_CFLAGS
 
 AC_MSG_CHECKING([if __get_cpuid_count exists])
-AC_COMPILE_IFELSE(
+AC_LINK_IFELSE(
   [AC_LANG_SOURCE([[
     #include <cpuid.h>
 
-- 
2.9.0

Reply via email to