bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ffsll: Override completely broken implementation on AIX in 32-bit mode


From: Bruno Haible
Subject: ffsll: Override completely broken implementation on AIX in 32-bit mode
Date: Tue, 05 Jan 2021 07:19:11 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; )

On AIX 7.2 in 32-bit mode, ffsll() is completely broken. In some
cases it returns the sign bit of the argument, in other cases always 1.

This patch provides an override.


2021-01-05  Bruno Haible  <bruno@clisp.org>

        ffsll: Override completely broken implementation on AIX in 32-bit mode.
        * m4/ffsll.m4 (gl_FUNC_FFSLL): Test whether ffsll minimally works. If
        not, set REPLACE_FFSLL.
        * lib/string.in.h (ffsll): Consider REPLACE_FFSLL.
        * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Initialize
        REPLACE_FFSLL.
        * modules/string (Makefile.am): Substitute REPLACE_FFSLL.
        * modules/ffsll (Depends-on, configure.ac): Consider REPLACE_FFSLL.
        * doc/glibc-functions/ffsll.texi: Mention the AIX 7.2 bug.

diff --git a/doc/glibc-functions/ffsll.texi b/doc/glibc-functions/ffsll.texi
index 718ccfc..41e701e 100644
--- a/doc/glibc-functions/ffsll.texi
+++ b/doc/glibc-functions/ffsll.texi
@@ -15,6 +15,9 @@ Mac OS X 10.5, FreeBSD 6.0, NetBSD 9.0, OpenBSD 6.7, Minix 
3.1.8, AIX 5.1, HP-UX
 This function is declared in @code{<strings.h>} instead of @code{<string.h>}
 on some platforms:
 AIX 7.2.
+@item
+This function returns completely wrong values on some platforms:
+AIX 7.2 in 32-bit mode.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/string.in.h b/lib/string.in.h
index 2f2e07b..bac515d 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -118,10 +118,18 @@ _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the 
ffsl module");
 
 /* Find the index of the least-significant set bit.  */
 #if @GNULIB_FFSLL@
-# if !@HAVE_FFSLL@
+# if @REPLACE_FFSLL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define ffsll rpl_ffsll
+#  endif
+_GL_FUNCDECL_RPL (ffsll, int, (long long int i));
+_GL_CXXALIAS_RPL (ffsll, int, (long long int i));
+# else
+#  if !@HAVE_FFSLL@
 _GL_FUNCDECL_SYS (ffsll, int, (long long int i));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (ffsll, int, (long long int i));
+# endif
 _GL_CXXALIASWARN (ffsll);
 #elif defined GNULIB_POSIXCHECK
 # undef ffsll
diff --git a/m4/ffsll.m4 b/m4/ffsll.m4
index f99ea9c..97491eb 100644
--- a/m4/ffsll.m4
+++ b/m4/ffsll.m4
@@ -1,4 +1,4 @@
-# ffsll.m4 serial 1
+# ffsll.m4 serial 2
 dnl Copyright (C) 2011-2021 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,12 +7,50 @@ dnl with or without modifications, as long as this notice is 
preserved.
 AC_DEFUN([gl_FUNC_FFSLL],
 [
   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
 
-  dnl Persuade glibc <string.h> to declare 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 = no; then
+  if test $ac_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],
+      [gl_cv_func_ffsll_works],
+      [AC_RUN_IFELSE(
+         [AC_LANG_SOURCE([[
+            #include <string.h>
+            #include <strings.h>
+            int dummy (long long x) { return 42; }
+            int main (int argc, char *argv[])
+            {
+              int (* volatile my_ffsll) (long long) = argc ? ffsll : dummy;
+              long long int x = -128LL;
+              return my_ffsll (x) != 8;
+            }
+          ]])],
+         [gl_cv_func_ffsll_works=yes],
+         [gl_cv_func_ffsll_works=no],
+         [case "$host_os" in
+                           # Guess yes on glibc systems.
+            *-gnu* | gnu*) gl_cv_func_ffsll_works="guessing yes" ;;
+                           # Guess yes on musl systems.
+            *-musl*)       gl_cv_func_ffsll_works="guessing yes" ;;
+                           # Guess yes on native Windows.
+            mingw*)        gl_cv_func_ffsll_works="guessing yes" ;;
+                           # Guess no on AIX.
+            aix*)          gl_cv_func_ffsll_works="guessing no" ;;
+                           # If we don't know, obey --enable-cross-guesses.
+            *)             gl_cv_func_ffsll_works="$gl_cross_guess_normal" ;;
+          esac
+         ])
+      ])
+    case "$gl_cv_func_ffsll_works" in
+      *yes) ;;
+      *) REPLACE_FFSLL=1 ;;
+    esac
+  else
     HAVE_FFSLL=0
   fi
 ])
diff --git a/m4/string_h.m4 b/m4/string_h.m4
index 3e65355..a4cc5b4 100644
--- a/m4/string_h.m4
+++ b/m4/string_h.m4
@@ -5,7 +5,7 @@
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 28
+# serial 29
 
 # Written by Paul Eggert.
 
@@ -113,6 +113,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
   HAVE_SIGDESCR_NP=1;           AC_SUBST([HAVE_SIGDESCR_NP])
   HAVE_DECL_STRSIGNAL=1;        AC_SUBST([HAVE_DECL_STRSIGNAL])
   HAVE_STRVERSCMP=1;            AC_SUBST([HAVE_STRVERSCMP])
+  REPLACE_FFSLL=0;              AC_SUBST([REPLACE_FFSLL])
   REPLACE_MEMCHR=0;             AC_SUBST([REPLACE_MEMCHR])
   REPLACE_MEMMEM=0;             AC_SUBST([REPLACE_MEMMEM])
   REPLACE_STPNCPY=0;            AC_SUBST([REPLACE_STPNCPY])
diff --git a/modules/ffsll b/modules/ffsll
index d1f78fb..dea0d97 100644
--- a/modules/ffsll
+++ b/modules/ffsll
@@ -9,11 +9,11 @@ m4/ffsll.m4
 Depends-on:
 extensions
 string
-ffs             [test $HAVE_FFSLL = 0]
+ffs             [test $HAVE_FFSLL = 0 || test $REPLACE_FFSLL = 1]
 
 configure.ac:
 gl_FUNC_FFSLL
-if test $HAVE_FFSLL = 0; then
+if test $HAVE_FFSLL = 0 || test $REPLACE_FFSLL = 1; then
   AC_LIBOBJ([ffsll])
 fi
 gl_STRING_MODULE_INDICATOR([ffsll])
diff --git a/modules/string b/modules/string
index 8ce11d2..6c87229 100644
--- a/modules/string
+++ b/modules/string
@@ -98,6 +98,7 @@ string.h: string.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''HAVE_SIGDESCR_NP''@|$(HAVE_SIGDESCR_NP)|g' \
              -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \
              -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \
+             -e 's|@''REPLACE_FFSLL''@|$(REPLACE_FFSLL)|g' \
              -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \
              -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
              -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \




reply via email to

[Prev in Thread] Current Thread [Next in Thread]