kdave / btrfs-progs

Development of userspace BTRFS tools
GNU General Public License v2.0
527 stars 239 forks source link

btrfs-progs: build: CPU feature checks compatible with clang #713

Closed vadorovsky closed 7 months ago

vadorovsky commented 7 months ago

Clang, unlike GCC, typically accepts unknown or unsupported -m options without error, simple ignoring them if they don't apply to the target architecture. This means that the AX_CHECK_COMPILE_FLAG macro, which relies on the compiler to fail when an unsupported flag is used, doesn't work as intended with clang.

This change fixes that by compiling test programs which make an actual use of tested flags. Such checks work reliably on clang.

Fixes: #712

kdave commented 7 months ago

Thanks. This does not seem to work on gcc 13.2.1:

checking whether the compiler supports -msse2... yes
checking whether the compiler supports -msse4.1... no
checking whether the compiler supports -mavx2... no  
checking whether the compiler supports -msha... no

and an example from config.log:

configure:5197: checking whether the compiler supports -msha
configure:5214: gcc -c -g -O1 -Wall -D_FORTIFY_SOURCE=2  conftest.c >&5
In file included from /usr/lib64/gcc/x86_64-suse-linux/13/include/immintrin.h:107,
                 from conftest.c:40:
/usr/lib64/gcc/x86_64-suse-linux/13/include/shaintrin.h: In function 'main':
/usr/lib64/gcc/x86_64-suse-linux/13/include/shaintrin.h:61:1: error: inlining failed in call to 'always_inline' '_mm_sha1rnds4_epu32': target specific option mismatch
   61 | _mm_sha1rnds4_epu32 (__m128i __A, __m128i __B, const int __I)
      | ^~~~~~~~~~~~~~~~~~~
conftest.c:47:9: note: called from here
   47 |     a = _mm_sha1rnds4_epu32(a, b, 0);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib64/gcc/x86_64-suse-linux/13/include/shaintrin.h:61:1: error: inlining failed in call to 'always_inline' '_mm_sha1rnds4_epu32': target specific option mismatch
   61 | _mm_sha1rnds4_epu32 (__m128i __A, __m128i __B, const int __I)
      | ^~~~~~~~~~~~~~~~~~~
conftest.c:47:9: note: called from here
   47 |     a = _mm_sha1rnds4_epu32(a, b, 0);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
configure:5214: $? = 1

So it's not related to the feature support itself.

kdave commented 7 months ago

Fixed in another way, the -m options are checked only on x86_64. In case there's some ARM -m support needed it's ok for now to add another 'if $target_cpu'.

vadorovsky commented 7 months ago

@kdave Thanks!

Sorry for lack of reply before. I was indeed able to reproduce the issue with GCC 13, but I didn't come up with any fix. Glad that you solved it in cleaner way.