bug-autoconf
[Top][All Lists]
Advanced

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

Re: AC_CHECK_ALIGNOF cross-compile detection fails with newer gcc and of


From: Paul Eggert
Subject: Re: AC_CHECK_ALIGNOF cross-compile detection fails with newer gcc and offsetof fallback
Date: Thu, 06 Sep 2012 14:59:23 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120827 Thunderbird/15.0

On 09/06/2012 12:00 PM, Mike Frysinger wrote:

> perhaps one fix would be for AC_CHECK_ALIGNOF to require AC_STDC_HEADERS ?

Better yet, let's assume the C89 freestanding headers
since that simplifies things.  It's safe to make that assumption these
days and we already do it elsewhere.  I pushed the following.


>From 91cd3fb1ea64567b40d9a55b94074e198dae964b Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Thu, 6 Sep 2012 14:50:27 -0700
Subject: [PATCH] AC_CHECK_ALIGNOF: fix cross-compilation bug with newer gcc

* doc/autoconf.texi (Default Includes, Particular Functions)
(Header Portability):
* lib/autoconf/c.m4 (AC_LANG_FUNC_LINK_TRY(C)):
* lib/autoconf/headers.m4 (AC_HEADER_STDC):
* lib/autoconf/types.m4 (_AC_CHECK_ALIGNOF):
* lib/m4sugar/m4sugar.m4 (m4_require) [comment only]:
Assume the existence of the C89 freestanding headers <float.h>,
<limits.h>, <stdarg.h>, <stddef.h>, as that's safe nowadays.
This is less likely to run into gotchas, and should fix a
cross-compilation bug with newer GCC reported by Myke Frysinger in
<http://lists.gnu.org/archive/html/bug-autoconf/2012-09/msg00001.html>.
---
 doc/autoconf.texi       | 32 ++++++++------------------------
 lib/autoconf/c.m4       | 19 +++----------------
 lib/autoconf/headers.m4 |  8 ++------
 lib/autoconf/types.m4   |  3 ---
 lib/m4sugar/m4sugar.m4  |  4 ++--
 5 files changed, 15 insertions(+), 51 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 3d2fe1a..7b8bfd5 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -3885,14 +3885,10 @@ Expand to @var{include-directives} if defined, 
otherwise to:
 #ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
-#ifdef STDC_HEADERS
+#if defined STDC_HEADERS || defined HAVE_STDLIB_H
 # include <stdlib.h>
-# include <stddef.h>
-#else
-# ifdef HAVE_STDLIB_H
-#  include <stdlib.h>
-# endif
 #endif
+#include <stddef.h>
 #ifdef HAVE_STRING_H
 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
 #  include <memory.h>
@@ -4862,14 +4858,10 @@ like the following, to declare it properly.
 
 @example
 @group
-#ifdef STDC_HEADERS
+#if defined STDC_HEADERS || defined HAVE_STDLIB_H
 # include <stdlib.h>
-# include <stddef.h>
-#else
-# ifdef HAVE_STDLIB_H
-#  include <stdlib.h>
-# endif
 #endif
+#include <stddef.h>
 #ifdef HAVE_ALLOCA_H
 # include <alloca.h>
 #elif !defined alloca
@@ -5764,14 +5756,10 @@ beforehand.  One should run:
 AC_CHECK_HEADERS([sys/socket.h])
 AC_CHECK_HEADERS([net/if.h], [], [],
 [#include <stdio.h>
-#ifdef STDC_HEADERS
+#if defined STDC_HEADERS || defined HAVE_STDLIB_H
 # include <stdlib.h>
-# include <stddef.h>
-#else
-# ifdef HAVE_STDLIB_H
-#  include <stdlib.h>
-# endif
 #endif
+#include <stddef.h>
 #ifdef HAVE_SYS_SOCKET_H
 # include <sys/socket.h>
 #endif
@@ -5787,14 +5775,10 @@ On Darwin, this file requires that @file{stdio.h} and
 AC_CHECK_HEADERS([sys/socket.h])
 AC_CHECK_HEADERS([netinet/if_ether.h], [], [],
 [#include <stdio.h>
-#ifdef STDC_HEADERS
+#if defined STDC_HEADERS || defined HAVE_STDLIB_H
 # include <stdlib.h>
-# include <stddef.h>
-#else
-# ifdef HAVE_STDLIB_H
-#  include <stdlib.h>
-# endif
 #endif
+#include <stddef.h>
 #ifdef HAVE_SYS_SOCKET_H
 # include <sys/socket.h>
 #endif
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 7337245..e994609 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -154,16 +154,9 @@ m4_define([AC_LANG_FUNC_LINK_TRY(C)],
 #define $1 innocuous_$1
 
 /* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char $1 (); below.
-    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-    <limits.h> exists even on freestanding compilers.  */
-
-#ifdef __STDC__
-# include <limits.h>
-#else
-# include <assert.h>
-#endif
+   which can conflict with char $1 (); below.  */
 
+#include <limits.h>
 #undef $1
 
 /* Override any GCC internal prototype to avoid an error.
@@ -348,15 +341,9 @@ for ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag in '' yes
 do
   # Use a header file that comes with gcc, so configuring glibc
   # with a fresh cross-compiler works.
-  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
-  # <limits.h> exists even on freestanding compilers.
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp. "Syntax error" is here to catch this case.
-  _AC_PREPROC_IFELSE([AC_LANG_SOURCE(address@hidden:@ifdef __STDC__
address@hidden:@ include <limits.h>
address@hidden:@else
address@hidden:@ include <assert.h>
address@hidden:@endif
+  _AC_PREPROC_IFELSE([AC_LANG_SOURCE(address@hidden:@include <limits.h>
                     Syntax error]])],
                     [],
                     [# Broken: fails on valid input.
diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 81a7fa2..58a2778 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -306,14 +306,10 @@ ac_includes_default="\
 #ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
-#ifdef STDC_HEADERS
+#if defined STDC_HEADERS || defined HAVE_STDLIB_H
 # include <stdlib.h>
-# include <stddef.h>
-#else
-# ifdef HAVE_STDLIB_H
-#  include <stdlib.h>
-# endif
 #endif
+#include <stddef.h>
 #ifdef HAVE_STRING_H
 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
 #  include <memory.h>
diff --git a/lib/autoconf/types.m4 b/lib/autoconf/types.m4
index 18fc175..f9ba33d 100644
--- a/lib/autoconf/types.m4
+++ b/lib/autoconf/types.m4
@@ -808,9 +808,6 @@ m4_define([_AC_CHECK_ALIGNOF],
 _AC_CACHE_CHECK_INT([alignment of $1], [AS_TR_SH([ac_cv_alignof_$3])],
   [(long int) offsetof (ac__type_alignof_, y)],
   [AC_INCLUDES_DEFAULT([$2])
-#ifndef offsetof
-# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
-#endif
 typedef struct { char x; $1 y; } ac__type_alignof_;],
   [if test "$AS_TR_SH([ac_cv_type_$3])" = yes; then
      AC_MSG_FAILURE([cannot compute alignment of $1], 77)
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 278bc05..12a9ab7 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -2038,10 +2038,10 @@ m4_define([m4_before],
 # - NAME-TO-CHECK == BODY-TO-EXPAND
 #   Which you can use for regular macros with or without arguments, e.g.,
 #     m4_require([AC_PROG_CC], [AC_PROG_CC])
-#     m4_require([AC_CHECK_HEADERS(limits.h)], [AC_CHECK_HEADERS(limits.h)])
+#     m4_require([AC_CHECK_HEADERS(threads.h)], [AC_CHECK_HEADERS(threads.h)])
 #   which is just the same as
 #     m4_require([AC_PROG_CC])
-#     m4_require([AC_CHECK_HEADERS(limits.h)])
+#     m4_require([AC_CHECK_HEADERS(threads.h)])
 #
 # - BODY-TO-EXPAND == m4_indir([NAME-TO-CHECK])
 #   In the case of macros with irregular names.  For instance:
-- 
1.7.11.4





reply via email to

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