From: Bruno Haible Date: Tue, 3 Jan 2023 20:33:32 +0000 (+0100) Subject: ffsl, ffsll: Fix compilation error on Android. X-Git-Tag: v1.0~1907 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=7c4ee88821d4ee0adc6511a0f6ead0e5ed6518b2;p=gnulib.git ffsl, ffsll: Fix compilation error on Android. * lib/string.in.h: On Android as well, include . * m4/ffsl.m4 (gl_FUNC_FFSL): Use a specific link test instead of AC_CHECK_FUNCS_ONCE. * m4/ffsll.m4 (gl_FUNC_FFSLL): Likewise. * doc/glibc-functions/ffsl.texi: Mention Android problems. * doc/glibc-functions/ffsll.texi: Likewise. --- diff --git a/ChangeLog b/ChangeLog index fc20f7ebe4..59a916a13a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2023-01-03 Bruno Haible + ffsl, ffsll: Fix compilation error on Android. + * lib/string.in.h: On Android as well, include . + * m4/ffsl.m4 (gl_FUNC_FFSL): Use a specific link test instead of + AC_CHECK_FUNCS_ONCE. + * m4/ffsll.m4 (gl_FUNC_FFSLL): Likewise. + * doc/glibc-functions/ffsl.texi: Mention Android problems. + * doc/glibc-functions/ffsll.texi: Likewise. + ffs: Document Android problem. * doc/posix-functions/ffs.texi: Mention Android problem. * m4/ffs.m4: Update comment. diff --git a/doc/glibc-functions/ffsl.texi b/doc/glibc-functions/ffsl.texi index 441383cc38..fa80a5cb28 100644 --- a/doc/glibc-functions/ffsl.texi +++ b/doc/glibc-functions/ffsl.texi @@ -14,9 +14,12 @@ FreeBSD 5.2.1, NetBSD 9.0, OpenBSD 6.7, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5 @item This function is declared in @code{} instead of @code{} on some platforms: -AIX 7.2. +AIX 7.2, Android 13. @end itemize Portability problems not fixed by Gnulib: @itemize +@item +This function is only defined as an inline function on some platforms: +Android 13. @end itemize diff --git a/doc/glibc-functions/ffsll.texi b/doc/glibc-functions/ffsll.texi index 41e701e87e..7912d451fc 100644 --- a/doc/glibc-functions/ffsll.texi +++ b/doc/glibc-functions/ffsll.texi @@ -14,7 +14,7 @@ Mac OS X 10.5, FreeBSD 6.0, NetBSD 9.0, OpenBSD 6.7, Minix 3.1.8, AIX 5.1, HP-UX @item This function is declared in @code{} instead of @code{} on some platforms: -AIX 7.2. +AIX 7.2, Android 13. @item This function returns completely wrong values on some platforms: AIX 7.2 in 32-bit mode. @@ -22,4 +22,7 @@ AIX 7.2 in 32-bit mode. Portability problems not fixed by Gnulib: @itemize +@item +This function is only defined as an inline function on some platforms: +Android 13. @end itemize diff --git a/lib/string.in.h b/lib/string.in.h index e993b2fb6f..b2683b6e4c 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -59,10 +59,11 @@ # include #endif -/* AIX 7.2 declares ffsl and ffsll in , not in . */ +/* AIX 7.2 and Android 13 declare ffsl and ffsll in , not in + . */ /* But in any case avoid namespace pollution on glibc systems. */ #if ((@GNULIB_FFSL@ || @GNULIB_FFSLL@ || defined GNULIB_POSIXCHECK) \ - && defined _AIX) \ + && (defined _AIX || defined __ANDROID__)) \ && ! defined __GLIBC__ # include #endif diff --git a/m4/ffsl.m4 b/m4/ffsl.m4 index 1d840e5b80..568e47cdaf 100644 --- a/m4/ffsl.m4 +++ b/m4/ffsl.m4 @@ -1,4 +1,4 @@ -# ffsl.m4 serial 2 +# ffsl.m4 serial 3 dnl Copyright (C) 2011-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -11,8 +11,26 @@ AC_DEFUN([gl_FUNC_FFSL], dnl Persuade glibc to declare ffsl(). AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - AC_CHECK_FUNCS_ONCE([ffsl]) - if test $ac_cv_func_ffsl = no; then + dnl We can't use AC_CHECK_FUNC here, because ffsl() is defined as a + dnl static inline function when compiling for Android 13 or older. + dnl But require that ffsl() is declared; otherwise we may be using + dnl the GCC built-in function, which leads to warnings + dnl "warning: implicit declaration of function 'ffsl'". + AC_CACHE_CHECK([for ffsl], [gl_cv_func_ffsl], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + long x; + ]], + [[int (*func) (long) = ffsl; + return func (x); + ]]) + ], + [gl_cv_func_ffsl=yes], + [gl_cv_func_ffsl=no]) + ]) + if test $gl_cv_func_ffsl = no; then HAVE_FFSL=0 fi ]) diff --git a/m4/ffsll.m4 b/m4/ffsll.m4 index 8414272c6e..d2bffe6e81 100644 --- a/m4/ffsll.m4 +++ b/m4/ffsll.m4 @@ -1,4 +1,4 @@ -# ffsll.m4 serial 3 +# ffsll.m4 serial 4 dnl Copyright (C) 2011-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,8 +12,26 @@ AC_DEFUN([gl_FUNC_FFSLL], dnl Persuade glibc and AIX to declare ffsll(). AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - AC_CHECK_FUNCS_ONCE([ffsll]) - if test $ac_cv_func_ffsll = yes; then + dnl We can't use AC_CHECK_FUNC here, because ffsll() is defined as a + dnl static inline function when compiling for Android 13 or older. + dnl But require that ffsll() is declared; otherwise we may be using + dnl the GCC built-in function, which leads to warnings + dnl "warning: implicit declaration of function 'ffsll'". + AC_CACHE_CHECK([for ffsll], [gl_cv_func_ffsll], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + long long x; + ]], + [[int (*func) (long long) = ffsll; + return func (x); + ]]) + ], + [gl_cv_func_ffsll=yes], + [gl_cv_func_ffsll=no]) + ]) + if test $gl_cv_func_ffsll = yes; then dnl Test whether ffsll works. dnl On AIX 7.2 in 32-bit mode it is completely broken. AC_CACHE_CHECK([whether ffsll works],