Hi, when cross-compiling with gcc >= 4.5 (I think), AC_CHECK_ALIGNOF fails to detect the alignment. This happens because the compiler fails with "error: storage size of ‘test_array’ isn’t constant" instead of succeeding. Using __builtin_offsetof helps. Patch attached. I'm not quite sure when __builtin_offsetof should be used, but it is used in the Linux kernel for gcc 4.x, so I think this is correct.
Regards, Michael -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
From: Michael Olbrich <m.olbr...@pengutronix.de> Date: Wed, 25 Apr 2012 10:16:58 +0200 Subject: [PATCH] fix AC_CHECK_ALIGNOF when cross-compiling with gcc >= 4.5 Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de> --- lib/autoconf/types.m4 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/autoconf/types.m4 b/lib/autoconf/types.m4 index 9f482da..15fa603 100644 --- a/lib/autoconf/types.m4 +++ b/lib/autoconf/types.m4 @@ -800,8 +800,12 @@ 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) +#if __GNUC_PREREQ(4,0) +# define offsetof(type, member) __builtin_offsetof(type, member) +#else +# ifndef offsetof +# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0) +# endif #endif typedef struct { char x; $1 y; } ac__type_alignof_;], [if test "$AS_TR_SH([ac_cv_type_$3])" = yes; then
signature.asc
Description: Digital signature