Building a Gnulib testdir on Android (via Termux), I see these errors:
clang -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -DNO_XMALLOC -DEXEEXT=\"\" -I. -I../../gllib -I.. -DGNULIB_STRICT_CHECKING=1 -I/data/data/com.termux/files/home/local/include -Wall -fvisibility=hidden -g -O2 -c -o ffsl.o ../../gllib/ffsl.c In file included from ../../gllib/ffsl.c:22: ../../gllib/ffsl.h:51:1: error: redefinition of 'ffsl' FUNC (TYPE i) ^ ../../gllib/ffsl.c:18:14: note: expanded from macro 'FUNC' #define FUNC ffsl ^ /data/data/com.termux/files/usr/include/strings.h:92:29: note: previous definition is here __BIONIC_STRINGS_INLINE int ffsl(long __n) { ^ 1 error generated. make[4]: *** [Makefile:10687: ffsl.o] Error 1 clang -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -DNO_XMALLOC -DEXEEXT=\"\" -I. -I../../gllib -I.. -DGNULIB_STRICT_CHECKING=1 -I/data/data/com.termux/files/home/local/include -Wall -fvisibility=hidden -g -O2 -c -o ffsll.o ../../gllib/ffsll.c In file included from ../../gllib/ffsll.c:24: ../../gllib/ffsl.h:51:1: error: redefinition of 'ffsll' FUNC (TYPE i) ^ ../../gllib/ffsll.c:18:14: note: expanded from macro 'FUNC' #define FUNC ffsll ^ /data/data/com.termux/files/usr/include/strings.h:103:29: note: previous definition is here __BIONIC_STRINGS_INLINE int ffsll(long long __n) { ^ 1 error generated. make[4]: *** [Makefile:10687: ffsll.o] Error 1 The attached patches fixes them.
>From 0ff4d2d5894ec53eb8bc8930266e3e8e93f5b51b Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 3 Jan 2023 19:48:59 +0100 Subject: [PATCH 1/2] ffs: Document Android problem. * doc/posix-functions/ffs.texi: Mention Android problem. * m4/ffs.m4: Update comment. --- ChangeLog | 6 ++++++ doc/posix-functions/ffs.texi | 3 +++ m4/ffs.m4 | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88d5faa592..fc20f7ebe4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-01-03 Bruno Haible <br...@clisp.org> + + ffs: Document Android problem. + * doc/posix-functions/ffs.texi: Mention Android problem. + * m4/ffs.m4: Update comment. + 2023-01-03 Bruno Haible <br...@clisp.org> stdio: Fix error in C++ mode on Android, due to putw. diff --git a/doc/posix-functions/ffs.texi b/doc/posix-functions/ffs.texi index 2e65b2f712..69f897a7f8 100644 --- a/doc/posix-functions/ffs.texi +++ b/doc/posix-functions/ffs.texi @@ -15,4 +15,7 @@ mingw, MSVC 14. 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/m4/ffs.m4 b/m4/ffs.m4 index 3bc6f8eca8..848fd0aa1f 100644 --- a/m4/ffs.m4 +++ b/m4/ffs.m4 @@ -1,4 +1,4 @@ -# ffs.m4 serial 5 +# ffs.m4 serial 6 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, @@ -9,7 +9,7 @@ AC_DEFUN([gl_FUNC_FFS], AC_REQUIRE([gl_STRINGS_H_DEFAULTS]) dnl We can't use AC_CHECK_FUNC here, because ffs() is defined as a - dnl static inline function when compiling for Android 4.2 or older. + dnl static inline function when compiling for Android 13 or older. dnl But require that ffs() is declared; otherwise we may be using dnl the GCC built-in function, which leads to warnings dnl "warning: implicit declaration of function 'ffs'". -- 2.34.1
>From 7c4ee88821d4ee0adc6511a0f6ead0e5ed6518b2 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 3 Jan 2023 21:33:32 +0100 Subject: [PATCH 2/2] ffsl, ffsll: Fix compilation error on Android. * lib/string.in.h: On Android as well, include <strings.h>. * 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. --- ChangeLog | 8 ++++++++ doc/glibc-functions/ffsl.texi | 5 ++++- doc/glibc-functions/ffsll.texi | 5 ++++- lib/string.in.h | 5 +++-- m4/ffsl.m4 | 24 +++++++++++++++++++++--- m4/ffsll.m4 | 24 +++++++++++++++++++++--- 6 files changed, 61 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc20f7ebe4..59a916a13a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2023-01-03 Bruno Haible <br...@clisp.org> + ffsl, ffsll: Fix compilation error on Android. + * lib/string.in.h: On Android as well, include <strings.h>. + * 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{<strings.h>} instead of @code{<string.h>} 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{<strings.h>} instead of @code{<string.h>} 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 <unistd.h> #endif -/* AIX 7.2 declares ffsl and ffsll in <strings.h>, not in <string.h>. */ +/* AIX 7.2 and Android 13 declare ffsl and ffsll in <strings.h>, not in + <string.h>. */ /* 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 <strings.h> #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 <string.h> 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 <string.h> + #include <strings.h> + 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 <string.h> and AIX <strings.h> 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 <string.h> + #include <strings.h> + 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], -- 2.34.1