From e182feb2ce14200db52b3a4a2491119367d8c5e6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 5 Jan 2021 07:15:09 +0100 Subject: [PATCH] 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. --- ChangeLog | 12 ++++++++++++ doc/glibc-functions/ffsll.texi | 3 +++ lib/string.in.h | 12 ++++++++++-- m4/ffsll.m4 | 44 +++++++++++++++++++++++++++++++++++++++--- m4/string_h.m4 | 3 ++- modules/ffsll | 4 ++-- modules/string | 1 + 7 files changed, 71 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2663445a73..19f9046ede 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2021-01-05 Bruno Haible + + 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. + 2021-01-04 Bruno Haible symlinkat: Fix trailing slash handling. diff --git a/doc/glibc-functions/ffsll.texi b/doc/glibc-functions/ffsll.texi index 718ccfcafe..41e701e87e 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{} instead of @code{} 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 2f2e07bd77..bac515dce2 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 f99ea9c74e..97491eb2e6 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 to declare 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 = 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 + #include + 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 3e65355735..a4cc5b4378 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 d1f78fb8ba..dea0d97e80 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 8ce11d24ac..6c87229e4c 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' \ -- 2.11.4.GIT