Configure outputs when cross-compiling: checking for GNU libc compatible malloc... no checking for GNU libc compatible realloc... no
Here's a proposed patch for improving the guess for glibc targets. Again, the question is whether to modify the macro in Autoconf proper. 2012-05-01 Bruno Haible <br...@clisp.org> *alloc-gnu, eealloc: Avoid "guessing no" when cross-compiling to glibc. * m4/malloc.m4 (_gl_FUNC_MALLOC_IF): New macro. (gl_FUNC_MALLOC_GNU): Invoke it instead of _AC_FUNC_MALLOC_IF. * m4/realloc.m4 (_gl_FUNC_REALLOC_IF): New macro. (gl_FUNC_REALLOC_GNU): Invoke it instead of _AC_FUNC_REALLOC_IF. * m4/calloc.m4 (_AC_FUNC_CALLOC_IF): Require AC_CANONICAL_HOST. When cross-compiling, choose the first alternative on glibc systems. * m4/eealloc.m4 (gl_EEMALLOC): Require AC_CANONICAL_HOST. When cross-compiling, set gl_cv_func_malloc_0_nonnull to 1 on glibc systems. (gl_EEREALLOC): Require AC_CANONICAL_HOST. When cross-compiling, set gl_cv_func_realloc_0_nonnull to 1 on glibc systems. --- m4/malloc.m4.orig Tue May 1 23:34:29 2012 +++ m4/malloc.m4 Tue May 1 23:27:22 2012 @@ -1,9 +1,32 @@ -# malloc.m4 serial 13 +# malloc.m4 serial 14 dnl Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. +# _gl_FUNC_MALLOC_IF([IF-WORKS], [IF-NOT]) +# ---------------------------------------- +# Like _AC_FUNC_MALLOC_IF, defined in Autoconf, with improved cross-compilation +# guess. +AC_DEFUN([_gl_FUNC_MALLOC_IF], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + if test $cross_compiling = no; then + _AC_FUNC_MALLOC_IF([$1], [$2]) + else + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) + $1 + ;; + # If we don't know, assume the worst. + *) + $2 + ;; + esac + fi +]) + # gl_FUNC_MALLOC_GNU # ------------------ # Test whether 'malloc (0)' is handled like in GNU libc, and replace malloc if @@ -11,8 +34,7 @@ AC_DEFUN([gl_FUNC_MALLOC_GNU], [ AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) - dnl _AC_FUNC_MALLOC_IF is defined in Autoconf. - _AC_FUNC_MALLOC_IF( + _gl_FUNC_MALLOC_IF( [AC_DEFINE([HAVE_MALLOC_GNU], [1], [Define to 1 if your system has a GNU libc compatible 'malloc' function, and to 0 otherwise.])], --- m4/realloc.m4.orig Tue May 1 23:34:29 2012 +++ m4/realloc.m4 Tue May 1 23:28:35 2012 @@ -1,9 +1,32 @@ -# realloc.m4 serial 12 +# realloc.m4 serial 13 dnl Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. +# _gl_FUNC_REALLOC_IF([IF-WORKS], [IF-NOT]) +# ---------------------------------------- +# Like _AC_FUNC_REALLOC_IF, defined in Autoconf, with improved cross-compilation +# guess. +AC_DEFUN([_gl_FUNC_REALLOC_IF], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + if test $cross_compiling = no; then + _AC_FUNC_REALLOC_IF([$1], [$2]) + else + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) + $1 + ;; + # If we don't know, assume the worst. + *) + $2 + ;; + esac + fi +]) + # gl_FUNC_REALLOC_GNU # ------------------- # Test whether 'realloc (0, 0)' is handled like in GNU libc, and replace @@ -11,8 +34,7 @@ AC_DEFUN([gl_FUNC_REALLOC_GNU], [ AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) - dnl _AC_FUNC_REALLOC_IF is defined in Autoconf. - _AC_FUNC_REALLOC_IF( + _gl_FUNC_REALLOC_IF( [AC_DEFINE([HAVE_REALLOC_GNU], [1], [Define to 1 if your system has a GNU libc compatible 'realloc' function, and to 0 otherwise.])], --- m4/calloc.m4.orig Tue May 1 23:34:29 2012 +++ m4/calloc.m4 Tue May 1 23:34:08 2012 @@ -1,4 +1,4 @@ -# calloc.m4 serial 14 +# calloc.m4 serial 15 # Copyright (C) 2004-2012 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -18,6 +18,7 @@ AC_DEFUN([_AC_FUNC_CALLOC_IF], [ AC_REQUIRE([AC_TYPE_SIZE_T])dnl + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles AC_CACHE_CHECK([for GNU libc compatible calloc], [ac_cv_func_calloc_0_nonnull], [AC_RUN_IFELSE( @@ -32,8 +33,21 @@ ]])], [ac_cv_func_calloc_0_nonnull=yes], [ac_cv_func_calloc_0_nonnull=no], - [ac_cv_func_calloc_0_nonnull=no])]) - AS_IF([test $ac_cv_func_calloc_0_nonnull = yes], [$1], [$2]) + [case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) ac_cv_func_calloc_0_nonnull="guessing yes" ;; + # If we don't know, assume the worst. + *) ac_cv_func_calloc_0_nonnull="guessing no" ;; + esac + ])]) + case "$ac_cv_func_calloc_0_nonnull" in + *yes) + $1 + ;; + *) + $2 + ;; + esac ])# AC_FUNC_CALLOC --- m4/eealloc.m4.orig Tue May 1 23:34:29 2012 +++ m4/eealloc.m4 Tue May 1 23:32:47 2012 @@ -1,4 +1,4 @@ -# eealloc.m4 serial 2 +# eealloc.m4 serial 3 dnl Copyright (C) 2003, 2009-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -13,9 +13,20 @@ AC_DEFUN([gl_EEMALLOC], [ - _AC_FUNC_MALLOC_IF( - [gl_cv_func_malloc_0_nonnull=1], - [gl_cv_func_malloc_0_nonnull=0]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + if test $cross_compiling = no; then + _AC_FUNC_MALLOC_IF( + [gl_cv_func_malloc_0_nonnull=1], + [gl_cv_func_malloc_0_nonnull=0]) + else + dnl Improved cross-compilation guess. + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_malloc_0_nonnull=1 ;; + # If we don't know, assume the worst. + *) gl_cv_func_malloc_0_nonnull=0 ;; + esac + fi AC_DEFINE_UNQUOTED([MALLOC_0_IS_NONNULL], [$gl_cv_func_malloc_0_nonnull], [If malloc(0) is != NULL, define this to 1. Otherwise define this to 0.]) @@ -23,9 +34,20 @@ AC_DEFUN([gl_EEREALLOC], [ - _AC_FUNC_REALLOC_IF( - [gl_cv_func_realloc_0_nonnull=1], - [gl_cv_func_realloc_0_nonnull=0]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + if test $cross_compiling = no; then + _AC_FUNC_REALLOC_IF( + [gl_cv_func_realloc_0_nonnull=1], + [gl_cv_func_realloc_0_nonnull=0]) + else + dnl Improved cross-compilation guess. + case "$host_os" in + # Guess yes on glibc systems. + *-gnu*) gl_cv_func_realloc_0_nonnull=1 ;; + # If we don't know, assume the worst. + *) gl_cv_func_realloc_0_nonnull=0 ;; + esac + fi AC_DEFINE_UNQUOTED([REALLOC_0_IS_NONNULL], [$gl_cv_func_realloc_0_nonnull], [If realloc(NULL,0) is != NULL, define this to 1. Otherwise define this to 0.])