From 00f35b4ae7f94e0fe1c8c77efec401ab5f3c4855 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 22 Oct 2015 12:54:45 -0700 Subject: Move pointer size detection entirely to qprocessordetection.h This commit removes the legacy ptrsize check, which was deficient because it did not work for multiarch systems (when we supported fat OS X binaries) and did not work for bootstrap builds because the size might be different when cross-compiling. Instead, let's rely on the predefined preprocessor macros to detect correctly. As a nice side-effect, this fixes 64-bit Android builds cross-compiled from Windows. Task-number: QTBUG-48932 Change-Id: I1d0f78915b5942aab07cffff140f9a52b9342f23 Reviewed-by: Oswald Buddenhagen Reviewed-by: Erik Verbruggen --- src/corelib/global/qprocessordetection.h | 35 ++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/corelib/global/qprocessordetection.h') diff --git a/src/corelib/global/qprocessordetection.h b/src/corelib/global/qprocessordetection.h index a026224021..4b75872bb6 100644 --- a/src/corelib/global/qprocessordetection.h +++ b/src/corelib/global/qprocessordetection.h @@ -91,6 +91,7 @@ # define Q_PROCESSOR_ARM # if defined(__aarch64__) # define Q_PROCESSOR_ARM_64 +# define Q_PROCESSOR_WORDSIZE 8 # else # define Q_PROCESSOR_ARM_32 # endif @@ -228,6 +229,7 @@ # endif # if defined(_MIPS_ARCH_MIPS64) || defined(__mips64) # define Q_PROCESSOR_MIPS_64 +# define Q_PROCESSOR_WORDSIZE 8 # endif # if defined(__MIPSEL__) # define Q_BYTE_ORDER Q_LITTLE_ENDIAN @@ -252,6 +254,7 @@ # define Q_PROCESSOR_POWER # if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__) # define Q_PROCESSOR_POWER_64 +# define Q_PROCESSOR_WORDSIZE 8 # else # define Q_PROCESSOR_POWER_32 # endif @@ -322,6 +325,28 @@ # endif #endif +/* + Size of a pointer and the machine register size. We detect a 64-bit system by: + * GCC and compatible compilers (Clang, ICC on OS X and Windows) always define + __SIZEOF_POINTER__. This catches all known cases of ILP32 builds on 64-bit + processors. + * Most other Unix compilers define __LP64__ or _LP64 on 64-bit mode + (Long and Pointer 64-bit) + * If Q_PROCESSOR_WORDSIZE was defined above, it's assumed to match the pointer + size. + Otherwise, we assume to be 32-bit and then check in qglobal.cpp that it is right. +*/ + +#if defined __SIZEOF_POINTER__ +# define QT_POINTER_SIZE __SIZEOF_POINTER__ +#elif defined(__LP64__) || defined(_LP64) +# define QT_POINTER_SIZE 8 +#elif defined(Q_PROCESSOR_WORDSIZE) +# define QT_POINTER_SIZE Q_PROCESSOR_WORDSIZE +#else +# define QT_POINTER_SIZE 4 +#endif + /* Define Q_PROCESSOR_WORDSIZE to be the size of the machine's word (usually, the size of the register). On some architectures where a pointer could be @@ -330,14 +355,8 @@ Falls back to QT_POINTER_SIZE if not set explicitly for the platform. */ #ifndef Q_PROCESSOR_WORDSIZE -# ifdef __SIZEOF_POINTER__ - /* GCC & friends define this */ -# define Q_PROCESSOR_WORDSIZE __SIZEOF_POINTER__ -# elif defined(_LP64) || defined(__LP64__) || defined(WIN64) || defined(_WIN64) -# define Q_PROCESSOR_WORDSIZE 8 -# else -# define Q_PROCESSOR_WORDSIZE QT_POINTER_SIZE -# endif +# define Q_PROCESSOR_WORDSIZE QT_POINTER_SIZE #endif + #endif // QPROCESSORDETECTION_H -- cgit v1.2.3