[PATCH v2 16/28] x86: math: Use of __libgcc_cmp_return__ iff compiler supports it
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Oct 28 20:11:01 GMT 2025
On 28/10/25 16:38, H.J. Lu wrote:
> On Wed, Oct 29, 2025 at 1:13 AM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>
>> clang does not support '__attribute__ ((mode (__libgcc_cmp_return__)))',
>> so use a more close related type instead fo the default 'int'.
>> ---
>> config.h.in | 3 +++
>> sysdeps/x86/configure | 39 +++++++++++++++++++++++++++++++++++
>> sysdeps/x86/configure.ac | 18 ++++++++++++++++
>> sysdeps/x86/fpu/sfp-machine.h | 10 ++++++++-
>> 4 files changed, 69 insertions(+), 1 deletion(-)
>>
>> diff --git a/config.h.in b/config.h.in
>> index 5378883060..34da4d047e 100644
>> --- a/config.h.in
>> +++ b/config.h.in
>> @@ -317,4 +317,7 @@
>> /* Define if trunc is inlined on x86. */
>> #undef HAVE_X86_INLINE_TRUNC
>>
>> +/* Define if compiler suport __attribute__ ((mode (__libgcc_cmp_return__))). */
>> +#undef HAVE_X86_LIBGCC_CMP_RETURN_ATTR
>> +
>> #endif
>> diff --git a/sysdeps/x86/configure b/sysdeps/x86/configure
>> index 2e95277f29..ad205f6975 100644
>> --- a/sysdeps/x86/configure
>> +++ b/sysdeps/x86/configure
>> @@ -392,6 +392,45 @@ else
>>
>> fi
>>
>> +
>> +conftest_code="
>> +int __gcc_CMPtype_GCC __attribute__ ((mode (__libgcc_cmp_return__)));
>> +"
>> +
>> +cat > conftest.c <<EOF
>> +$conftest_code
>> +EOF
>> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __libgcc_cmp_return__ mode attribute support" >&5
>> +printf %s "checking for __libgcc_cmp_return__ mode attribute support... " >&6; }
>> +if test ${libc_cv_cc_x86_libgcc_cmp_return_attribute+y}
>> +then :
>> + printf %s "(cached) " >&6
>> +else case e in #(
>> + e) if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $CFLAGS conftest.c -o conftest 1>&5'
>> + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
>> + (eval $ac_try) 2>&5
>> + ac_status=$?
>> + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>> + test $ac_status = 0; }; }
>> + then
>> + libc_cv_cc_x86_libgcc_cmp_return_attribute=yes
>> + else
>> + libc_cv_cc_x86_libgcc_cmp_return_attribute=no
>> + fi ;;
>> +esac
>> +fi
>> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_x86_libgcc_cmp_return_attribute" >&5
>> +printf "%s\n" "$libc_cv_cc_x86_libgcc_cmp_return_attribute" >&6; }
>> +rm -f conftest*
>> +if test "$libc_cv_cc_x86_libgcc_cmp_return_attribute" = yes; then
>> + printf "%s\n" "#define HAVE_X86_LIBGCC_CMP_RETURN_ATTR 1" >>confdefs.h
>> +
>> +else
>> + printf "%s\n" "#define HAVE_X86_LIBGCC_CMP_RETURN_ATTR 0" >>confdefs.h
>> +
>> +fi
>> +
>> +
>> if test "${libc_cv_cc_no_direct_extern_access}${libc_cv_test_cc_cflags_no_direct_extern_access}" = yes; then
>> libc_cv_protected_data=no
>> fi
>> diff --git a/sysdeps/x86/configure.ac b/sysdeps/x86/configure.ac
>> index f3888e6618..e0500f21b4 100644
>> --- a/sysdeps/x86/configure.ac
>> +++ b/sysdeps/x86/configure.ac
>> @@ -223,6 +223,24 @@ else
>> AC_DEFINE(HAVE_X86_INLINE_TRUNC, 0)
>> fi
>>
>> +
>> +conftest_code="
>> +int __gcc_CMPtype_GCC __attribute__ ((mode (__libgcc_cmp_return__)));
>> +"
>> +dnl Check if CC support the __libgcc_cmp_return__ mode attribute
>> +LIBC_TRY_CC_COMMAND([for __libgcc_cmp_return__ mode attribute support],
>> + [$conftest_code],
>> + [$CFLAGS],
>> + libc_cv_cc_x86_libgcc_cmp_return_attribute,
>> + [libc_cv_cc_x86_libgcc_cmp_return_attribute=yes],
>> + [libc_cv_cc_x86_libgcc_cmp_return_attribute=no])
>> +if test "$libc_cv_cc_x86_libgcc_cmp_return_attribute" = yes; then
>> + AC_DEFINE(HAVE_X86_LIBGCC_CMP_RETURN_ATTR, 1)
>> +else
>> + AC_DEFINE(HAVE_X86_LIBGCC_CMP_RETURN_ATTR, 0)
>> +fi
>> +
>> +
>> dnl If the building compiler enables no direct external data access by
>> dnl default, access to protected data in shared libraries from executables
>> dnl must be compiled with no direct external data access. If the testing
>> diff --git a/sysdeps/x86/fpu/sfp-machine.h b/sysdeps/x86/fpu/sfp-machine.h
>> index cbcedb8621..9ef85c4e6c 100644
>> --- a/sysdeps/x86/fpu/sfp-machine.h
>> +++ b/sysdeps/x86/fpu/sfp-machine.h
>> @@ -1,9 +1,17 @@
>> /* Configure soft-fp for building sqrtf128. Based on sfp-machine.h in
>> libgcc, with soft-float and other irrelevant parts removed. */
>>
>> +#if HAVE_X86_LIBGCC_CMP_RETURN_ATTR
>> /* The type of the result of a floating point comparison. This must
>> match `__libgcc_cmp_return__' in GCC for the target. */
>> -typedef int __gcc_CMPtype __attribute__ ((mode (__libgcc_cmp_return__)));
>> +typedef int __gcc_CMPtype_GCC __attribute__ ((mode (__libgcc_cmp_return__)));
>> +#else
>> +# if defined __x86_64__ && defined __ILP32__
>
> Can you drop "&& defined __ILP32__"?
Ack.
>
>> +typedef long long int __gcc_CMPtype;
>> +#else
>> +typedef long int __gcc_CMPtype;
>> +# endif
>> +#endif
>> #define CMPtype __gcc_CMPtype
>>
>> #ifdef __x86_64__
>> --
>> 2.43.0
>>
>
>
More information about the Libc-alpha
mailing list