From 3d2f1071573cc171ceddd796fd911faabc491302 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Sun, 18 Mar 2012 23:21:09 -0700 Subject: [PATCH 2/2] fcarch: Check for architecture type at runtime rather than build time https://bugs.freedesktop.org/show_bug.cgi?id=20208 Signed-off-by: Jeremy Huddleston --- configure.in | 2 -- src/fcarch.h | 75 ++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/configure.in b/configure.in index 3204f2e..41a7d39 100644 --- a/configure.in +++ b/configure.in @@ -493,8 +493,6 @@ AC_SUBST(DOCMAN3) dnl Figure out what cache format suffix to use for this architecture AC_C_BIGENDIAN -AC_CHECK_SIZEOF([void *]) -AC_CHECK_ALIGNOF([double]) diff --git a/src/fcarch.h b/src/fcarch.h index 8695933..0675994 100644 --- a/src/fcarch.h +++ b/src/fcarch.h @@ -40,23 +40,27 @@ FC_ASSERT_STATIC (4 == sizeof (FcValueBinding)); FC_ASSERT_STATIC (8 == sizeof (FcAlign)); FC_ASSERT_STATIC (0x20 == sizeof (FcCharLeaf)); -FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (intptr_t)); -FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcPatternEltPtr)); -FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcValueListPtr)); -FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (char *)); -FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (struct FcPatternElt *)); -FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcValueList *)); -FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcStrSet *)); -FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcCharLeaf **)); -FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcChar16 *)); +FC_ASSERT_STATIC (sizeof(void *) == sizeof (intptr_t)); +FC_ASSERT_STATIC (sizeof(void *) == sizeof (FcPatternEltPtr)); +FC_ASSERT_STATIC (sizeof(void *) == sizeof (FcValueListPtr)); +FC_ASSERT_STATIC (sizeof(void *) == sizeof (char *)); +FC_ASSERT_STATIC (sizeof(void *) == sizeof (struct FcPatternElt *)); +FC_ASSERT_STATIC (sizeof(void *) == sizeof (FcValueList *)); +FC_ASSERT_STATIC (sizeof(void *) == sizeof (FcStrSet *)); +FC_ASSERT_STATIC (sizeof(void *) == sizeof (FcCharLeaf **)); +FC_ASSERT_STATIC (sizeof(void *) == sizeof (FcChar16 *)); -FC_ASSERT_STATIC (0x08 + 1*ALIGNOF_DOUBLE == sizeof (FcValue)); -FC_ASSERT_STATIC (0x00 + 2*SIZEOF_VOID_P == sizeof (FcPatternElt)); -FC_ASSERT_STATIC (0x08 + 2*SIZEOF_VOID_P == sizeof (FcPattern)); -FC_ASSERT_STATIC (0x08 + 2*SIZEOF_VOID_P == sizeof (FcCharSet)); -FC_ASSERT_STATIC (0x08 + 6*SIZEOF_VOID_P == sizeof (FcCache)); -#endif +FC_ASSERT_STATIC (0x08 + offsetof(struct { char c; double d; }, d) == sizeof (FcValue)); +FC_ASSERT_STATIC (0x00 + 2*sizeof(void *) == sizeof (FcPatternElt)); +FC_ASSERT_STATIC (0x08 + 2*sizeof(void *) == sizeof (FcPattern)); +FC_ASSERT_STATIC (0x08 + 2*sizeof(void *) == sizeof (FcCharSet)); +FC_ASSERT_STATIC (0x08 + 6*sizeof(void *) == sizeof (FcCache)); +#ifdef __APPLE__ +#include +#endif +#endif + /* * Each unique machine architecture needs an entry in this file * So far the differences boil down to: endianness, 32 vs 64 bit pointers, @@ -86,31 +90,36 @@ FC_ASSERT_STATIC (0x08 + 6*SIZEOF_VOID_P == sizeof (FcCache)); */ #define FC_ARCH_MAX_LEN 6 static inline int _FcGetArch(FcChar8 *buffer) { + const char *endian; + int ptr_bytes; + int dbl_align; + if (buffer == NULL) return EINVAL; -#if defined(WORDS_BIGENDIAN) && WORDS_BIGENDIAN -# define FC_ARCH_ENDIAN "be" -#else /* !WORDS_BIGENDIAN */ -# define FC_ARCH_ENDIAN "le" -#endif +#ifdef FC_ARCHITECTURE + /* If FC_ARCHITECTURE is set, use it */ + snprintf((char *) buffer, FC_ARCH_MAX_LEN + 1, "%s", FC_ARCHITECTURE); +#else -#if SIZEOF_VOID_P == 4 -# if ALIGNOF_DOUBLE == 4 -# define FC_ARCH_SIZE_ALIGN "32d4" -# else /* ALIGNOF_DOUBLE != 4 */ -# define FC_ARCH_SIZE_ALIGN "32d8" -# endif -#else /* SIZEOF_VOID_P != 4 */ -# define FC_ARCH_SIZE_ALIGN "64" +#if defined(__DARWIN_BYTE_ORDER) && __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN + endian = "le"; +#elif defined(__DARWIN_BYTE_ORDER) && __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN + endian = "be"; +#elif defined(__DARWIN_BYTE_ORDER) && __DARWIN_BYTE_ORDER == __DARWIN_PDP_ENDIAN + endian = "pe"; +#elif defined(WORDS_BIGENDIAN) && WORDS_BIGENDIAN + /* Fallback on what configure tells us */ + endian = "be"; +#else + endian = "le"; #endif -/* config.h might override this */ -#ifndef FC_ARCHITECTURE -# define FC_ARCHITECTURE FC_ARCH_ENDIAN FC_ARCH_SIZE_ALIGN -#endif + ptr_bytes = 8 * sizeof(void *); + dbl_align = offsetof(struct { char c; double d; }, d); - snprintf((char *) buffer, FC_ARCH_MAX_LEN + 1, "%s", FC_ARCHITECTURE); + snprintf((char *) buffer, FC_ARCH_MAX_LEN + 1, "%s%dd%d", endian, ptr_bytes, dbl_align); +#endif return 0; } -- 1.7.9.2