autoconf-patches
[Top][All Lists]
Advanced

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

[PATCH] Improve cross-compilation guesses for glibc system hosts.


From: Bruno Haible
Subject: [PATCH] Improve cross-compilation guesses for glibc system hosts.
Date: Wed, 02 May 2012 23:02:49 +0200
User-agent: KMail/4.7.4 (Linux/3.1.10-1.9-desktop; KDE/4.7.4; x86_64; ; )

Hi,

Paul and Eric suggested that improving the cross-compilation guesses
for targets that are glibc systems would be welcome here [1][2], so here
is a proposed patch.

This patch modifies the cross-compilation behaviour of
  AC_FUNC_CHOWN
  AC_FUNC_GETGROUPS
  AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
  AC_FUNC_MALLOC
  AC_FUNC_MMAP
  AC_FUNC_REALLOC
  AC_FUNC_STRCOLL
so that when the target is a glibc system (or, in case of AC_FUNC_MALLOC
and AC_FUNC_REALLOC, any known "good" Unix system), the guess is
"yes it works" rather than "guessing no".

This is important because some of these macros are used in Gnulib, and
in case of "guessing no" Gnulib provides extra workaround code, and
  1) Generally, when targetting embedded systems, code size should be
     minimized,
  2) In [3], unnecessary workaround code will look like a Glibc bug.

This patch also changes the configure output to "guessing yes" or
"guessing no" in a case where the ac_cv_* variable is undocumented.

[1] http://lists.gnu.org/archive/html/bug-gnulib/2012-05/msg00010.html
[2] http://lists.gnu.org/archive/html/bug-gnulib/2012-05/msg00013.html
[3] http://sourceware.org/glibc/wiki/Testing/Gnulib


This patch was tested as follows: The simple configure.ac file
=============== configure.ac ==================
AC_INIT([dummy], [0])
AC_FUNC_CHOWN
AC_FUNC_GETGROUPS
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_FUNC_STRCOLL
AC_OUTPUT
===============================================

produces this output when not cross-compiling:

$ ./configure --host=x86_64-pc-linux-gnu
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking for x86_64-pc-linux-gnu-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /arch/x86-linux/gnu/bin/grep
checking for egrep... /arch/x86-linux/gnu/bin/grep -E
checking for uid_t in sys/types.h... yes
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for unistd.h... (cached) yes
checking for working chown... yes
checking type of array argument to getgroups... gid_t
checking for size_t... yes
checking for getgroups... yes
checking for working getgroups... yes
checking whether lstat correctly handles trailing slash... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... yes
checking for getpagesize... yes
checking for working mmap... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible realloc... yes
checking for working strcoll... yes
configure: creating ./config.status

When cross-compiling it produces this before the patch:

$ ./configure --host=x86_64-pc-linux-gnu --build=x86_64-unknown-linux-gnu
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking for x86_64-pc-linux-gnu-gcc... no
checking for gcc... gcc
configure: WARNING: using cross tools not prefixed with host triplet
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /arch/x86-linux/gnu/bin/grep
checking for egrep... /arch/x86-linux/gnu/bin/grep -E
checking for uid_t in sys/types.h... yes
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for unistd.h... (cached) yes
checking for working chown... no
checking type of array argument to getgroups... gid_t
checking for size_t... yes
checking for getgroups... yes
checking for working getgroups... no
checking whether lstat correctly handles trailing slash... no
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... no
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... yes
checking for getpagesize... yes
checking for working mmap... no
checking for stdlib.h... (cached) yes
checking for GNU libc compatible realloc... no
checking for working strcoll... no
configure: creating ./config.status

and this output after the patch:

$ ./configure --host=x86_64-pc-linux-gnu --build=x86_64-unknown-linux-gnu
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking for x86_64-pc-linux-gnu-gcc... no
checking for gcc... gcc
configure: WARNING: using cross tools not prefixed with host triplet
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /arch/x86-linux/gnu/bin/grep
checking for egrep... /arch/x86-linux/gnu/bin/grep -E
checking for uid_t in sys/types.h... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for unistd.h... (cached) yes
checking for working chown... yes
checking type of array argument to getgroups... gid_t
checking for size_t... yes
checking for getgroups... yes
checking for working getgroups... guessing yes
checking whether lstat correctly handles trailing slash... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... yes
checking for getpagesize... yes
checking for working mmap... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible realloc... yes
checking for working strcoll... yes
configure: creating ./config.status


Patch comes here. The attachment contains the same thing in "git am" format.


        Improve cross-compilation guesses for glibc system hosts.

        * lib/autoconf/functions.m4 (AC_FUNC_CHOWN): Require AC_CANONICAL_HOST.
        When cross-compiling to a glibc system, guess yes.
        (AC_FUNC_GETGROUPS): Likewise.
        (AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK): Likewise.
        (AC_FUNC_STRCOLL): Likewise.
        (_AC_FUNC_MALLOC_IF): Require AC_CANONICAL_HOST. When cross-compiling
        to a know Unix system other than AIX and OSF/1, guess yes.
        (_AC_FUNC_REALLOC_IF): Likewise.
        (AC_FUNC_MMAP): Require AC_CANONICAL_HOST. When cross-compiling to a
        system with a Linux kernel, guess yes.

--- lib/autoconf/functions.m4.orig      Wed May  2 22:42:01 2012
+++ lib/autoconf/functions.m4   Wed May  2 22:33:44 2012
@@ -423,6 +423,7 @@
 AN_FUNCTION([chown], [AC_FUNC_CHOWN])
 AC_DEFUN([AC_FUNC_CHOWN],
 [AC_REQUIRE([AC_TYPE_UID_T])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
 AC_CHECK_HEADERS(unistd.h)
 AC_CACHE_CHECK([for working chown], ac_cv_func_chown_works,
 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
@@ -443,7 +444,12 @@
 ]])],
               [ac_cv_func_chown_works=yes],
               [ac_cv_func_chown_works=no],
-              [ac_cv_func_chown_works=no])
+              [case "$host_os" in # ((
+                         # Guess yes on glibc systems.
+                 *-gnu*) ac_cv_func_chown_works=yes ;;
+                         # If we don't know, assume the worst.
+                 *)      ac_cv_func_chown_works=no ;;
+               esac])
 rm -f conftest.chown
 ])
 if test $ac_cv_func_chown_works = yes; then
@@ -625,6 +631,7 @@
 AC_DEFUN([AC_FUNC_GETGROUPS],
 [AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
 AC_REQUIRE([AC_TYPE_SIZE_T])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
 AC_CHECK_FUNC(getgroups)
 
 # If we don't yet have getgroups, see if it's in -lbsd.
@@ -643,15 +650,22 @@
        return getgroups (0, 0) == -1;]])],
                  [ac_cv_func_getgroups_works=yes],
                  [ac_cv_func_getgroups_works=no],
-                 [ac_cv_func_getgroups_works=no])
+                 [case "$host_os" in # ((
+                            # Guess yes on glibc systems.
+                    *-gnu*) ac_cv_func_getgroups_works="guessing yes" ;;
+                            # If we don't know, assume the worst.
+                    *)      ac_cv_func_getgroups_works="guessing no" ;;
+                  esac])
    ])
 else
   ac_cv_func_getgroups_works=no
 fi
-if test $ac_cv_func_getgroups_works = yes; then
-  AC_DEFINE(HAVE_GETGROUPS, 1,
-           [Define to 1 if your system has a working `getgroups' function.])
-fi
+case "$ac_cv_func_getgroups_works" in
+  *yes)
+    AC_DEFINE(HAVE_GETGROUPS, 1,
+             [Define to 1 if your system has a working `getgroups' function.])
+    ;;
+esac
 LIBS=$ac_save_LIBS
 ])# AC_FUNC_GETGROUPS
 
@@ -847,7 +861,8 @@
 # calls lstat a second time when necessary.
 AN_FUNCTION([lstat], [AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
 AC_DEFUN([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK],
-[AC_CACHE_CHECK(
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
+AC_CACHE_CHECK(
        [whether lstat correctly handles trailing slash],
        [ac_cv_func_lstat_dereferences_slashed_symlink],
 [rm -f conftest.sym conftest.file
@@ -861,7 +876,12 @@
      return lstat ("conftest.sym/", &sbuf) == 0;])],
                [ac_cv_func_lstat_dereferences_slashed_symlink=yes],
                [ac_cv_func_lstat_dereferences_slashed_symlink=no],
-               [ac_cv_func_lstat_dereferences_slashed_symlink=no])
+               [case "$host_os" in # ((
+                          # Guess yes on glibc systems.
+                  *-gnu*) ac_cv_func_lstat_dereferences_slashed_symlink=yes ;;
+                          # If we don't know, assume the worst.
+                  *)      ac_cv_func_lstat_dereferences_slashed_symlink=no ;;
+                esac])
 else
   # If the `ln -s' command failed, then we probably don't even
   # have an lstat function.
@@ -886,6 +906,7 @@
 # If `malloc (0)' properly handled, run IF-WORKS, otherwise, IF-NOT.
 AC_DEFUN([_AC_FUNC_MALLOC_IF],
 [AC_REQUIRE([AC_HEADER_STDC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
 AC_CHECK_HEADERS(stdlib.h)
 AC_CACHE_CHECK([for GNU libc compatible malloc], ac_cv_func_malloc_0_nonnull,
 [AC_RUN_IFELSE(
@@ -899,7 +920,14 @@
                 [return ! malloc (0);])],
               [ac_cv_func_malloc_0_nonnull=yes],
               [ac_cv_func_malloc_0_nonnull=no],
-              [ac_cv_func_malloc_0_nonnull=no])])
+              [case "$host_os" in # ((
+                 # Guess yes on platforms where we know the result.
+                 *-gnu* | freebsd* | netbsd* | openbsd* \
+                 | hpux* | solaris* | cygwin* | mingw*)
+                   ac_cv_func_malloc_0_nonnull=yes ;;
+                 # If we don't know, assume the worst.
+                 *) ac_cv_func_malloc_0_nonnull=no ;;
+               esac])])
 AS_IF([test $ac_cv_func_malloc_0_nonnull = yes], [$1], [$2])
 ])# _AC_FUNC_MALLOC_IF
 
@@ -1199,7 +1227,8 @@
 # ------------
 AN_FUNCTION([mmap], [AC_FUNC_MMAP])
 AC_DEFUN([AC_FUNC_MMAP],
-[AC_CHECK_HEADERS_ONCE([stdlib.h unistd.h sys/param.h])
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
+AC_CHECK_HEADERS_ONCE([stdlib.h unistd.h sys/param.h])
 AC_CHECK_FUNCS([getpagesize])
 AC_CACHE_CHECK([for working mmap], [ac_cv_func_mmap_fixed_mapped],
 [AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
@@ -1340,7 +1369,12 @@
 }]])],
               [ac_cv_func_mmap_fixed_mapped=yes],
               [ac_cv_func_mmap_fixed_mapped=no],
-              [ac_cv_func_mmap_fixed_mapped=no])])
+              [case "$host_os" in # ((
+                         # Guess yes on platforms where we know the result.
+                 linux*) ac_cv_func_mmap_fixed_mapped=yes ;;
+                         # If we don't know, assume the worst.
+                 *)      ac_cv_func_mmap_fixed_mapped=no ;;
+               esac])])
 if test $ac_cv_func_mmap_fixed_mapped = yes; then
   AC_DEFINE([HAVE_MMAP], [1],
            [Define to 1 if you have a working `mmap' system call.])
@@ -1391,6 +1425,7 @@
 # If `realloc (0, 0)' is properly handled, run IF-WORKS, otherwise, IF-NOT.
 AC_DEFUN([_AC_FUNC_REALLOC_IF],
 [AC_REQUIRE([AC_HEADER_STDC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
 AC_CHECK_HEADERS(stdlib.h)
 AC_CACHE_CHECK([for GNU libc compatible realloc], ac_cv_func_realloc_0_nonnull,
 [AC_RUN_IFELSE(
@@ -1404,7 +1439,14 @@
                 [return ! realloc (0, 0);])],
               [ac_cv_func_realloc_0_nonnull=yes],
               [ac_cv_func_realloc_0_nonnull=no],
-              [ac_cv_func_realloc_0_nonnull=no])])
+              [case "$host_os" in # ((
+                 # Guess yes on platforms where we know the result.
+                 *-gnu* | freebsd* | netbsd* | openbsd* \
+                 | hpux* | solaris* | cygwin* | mingw*)
+                   ac_cv_func_realloc_0_nonnull=yes ;;
+                 # If we don't know, assume the worst.
+                 *) ac_cv_func_realloc_0_nonnull=no ;;
+               esac])])
 AS_IF([test $ac_cv_func_realloc_0_nonnull = yes], [$1], [$2])
 ])# AC_FUNC_REALLOC
 
@@ -1723,14 +1765,20 @@
 # ---------------
 AN_FUNCTION([strcoll], [AC_FUNC_STRCOLL])
 AC_DEFUN([AC_FUNC_STRCOLL],
-[AC_CACHE_CHECK(for working strcoll, ac_cv_func_strcoll_works,
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
+AC_CACHE_CHECK(for working strcoll, ac_cv_func_strcoll_works,
 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
   [[return (strcoll ("abc", "def") >= 0 ||
         strcoll ("ABC", "DEF") >= 0 ||
         strcoll ("123", "456") >= 0)]])],
               ac_cv_func_strcoll_works=yes,
               ac_cv_func_strcoll_works=no,
-              ac_cv_func_strcoll_works=no)])
+              [case "$host_os" in # ((
+                         # Guess yes on glibc systems.
+                 *-gnu*) ac_cv_func_strcoll_works=yes ;;
+                         # If we don't know, assume the worst.
+                 *)      ac_cv_func_strcoll_works=no ;;
+               esac])])
 if test $ac_cv_func_strcoll_works = yes; then
   AC_DEFINE(HAVE_STRCOLL, 1,
            [Define to 1 if you have the `strcoll' function and it is properly

Attachment: 0001-Improve-cross-compilation-guesses-for-glibc-system-h.patch
Description: Text Data


reply via email to

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