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 <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
Thiago Macieira 2015-10-22 12:54:45 -07:00
parent 3b447ae1f3
commit 00f35b4ae7
8 changed files with 28 additions and 134 deletions

View File

@ -1,35 +0,0 @@
#!/bin/sh
QMKSPEC=$1
VERBOSE=$2
SRCDIR=$3
OUTDIR=$4
LFLAGS=$SYSROOT_FLAG
CXXFLAGS=$SYSROOT_FLAG
# debuggery
[ "$VERBOSE" = "yes" ] && echo "Testing size of pointers ... ($*)"
# build and run a test program
test -d "$OUTDIR/config.tests/unix/ptrsize" || mkdir -p "$OUTDIR/config.tests/unix/ptrsize"
"$OUTDIR/bin/qmake" -nocache -spec "$QMKSPEC" "CONFIG-=app_bundle" "QMAKE_LFLAGS*=$LFLAGS" "QMAKE_CXXFLAGS*=$CXXFLAGS" "$SRCDIR/config.tests/unix/ptrsize/ptrsizetest.pro" -o "$OUTDIR/config.tests/unix/ptrsize/Makefile" >/dev/null 2>&1
cd "$OUTDIR/config.tests/unix/ptrsize"
if [ "$VERBOSE" = "yes" ]; then
($MAKE clean && $MAKE)
else
($MAKE clean && $MAKE) >/dev/null 2>&1
fi
RETVAL=$?
if [ "$RETVAL" -ne 0 ]; then
PTRSIZE=4
else
PTRSIZE=8
fi
# done
[ "$VERBOSE" = "yes" ] && echo "Pointer size: $PTRSIZE"
exit $PTRSIZE

View File

@ -1,53 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the config.tests of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
/* Sample program for configure to test pointer size on target
platforms.
*/
template<int>
struct QPointerSizeTest
{
};
template<>
struct QPointerSizeTest<8>
{
enum { PointerSize = 8 };
};
int main( int, char ** )
{
return QPointerSizeTest<sizeof(void*)>::PointerSize;
}

View File

@ -1,3 +0,0 @@
SOURCES = ptrsizetest.cpp
CONFIG -= qt dylib
CONFIG += debug console

13
configure vendored
View File

@ -6738,19 +6738,6 @@ if [ "$CFG_FRAMEWORK" = "yes" ]; then
echo "#define QT_MAC_FRAMEWORK_BUILD"
fi
if [ "$XPLATFORM_MAC" = "yes" ]; then
cat <<EOF
#if defined(__LP64__)
# define QT_POINTER_SIZE 8
#else
# define QT_POINTER_SIZE 4
#endif
EOF
else
"$unixtests/ptrsize.test" "$XQMAKESPEC" $OPT_VERBOSE "$relpath" "$outpath" >&3
echo "#define QT_POINTER_SIZE $?"
fi
if [ "$CFG_ATOMIC64" = "no" ]; then
echo "#define QT_NO_STD_ATOMIC64"
fi

View File

@ -120,9 +120,7 @@ Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n);
// (if this list becomes too long, consider factoring into a separate file)
Q_STATIC_ASSERT_X(sizeof(int) == 4, "Qt assumes that int is 32 bits");
Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
#ifndef QT_BOOTSTRAPPED
Q_STATIC_ASSERT_X(QT_POINTER_SIZE == sizeof(void *), "configure test ptrsize failed to correctly determine QT_POINTER_SIZE");
#endif
Q_STATIC_ASSERT_X(QT_POINTER_SIZE == sizeof(void *), "QT_POINTER_SIZE defined incorrectly");
/*!
\class QFlag

View File

@ -193,18 +193,6 @@ typedef unsigned long long quint64; /* 64 bit unsigned */
typedef qint64 qlonglong;
typedef quint64 qulonglong;
#ifndef QT_POINTER_SIZE
# if defined(Q_OS_WIN64) || (defined(Q_OS_WINRT) && defined(_M_X64))
# define QT_POINTER_SIZE 8
# elif defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT)
# define QT_POINTER_SIZE 4
# elif defined(Q_OS_ANDROID)
# define QT_POINTER_SIZE 4 // ### Add auto-detection to Windows configure
# elif !defined(QT_BOOTSTRAPPED)
# error could not determine QT_POINTER_SIZE
# endif
#endif
/*
Useful type definitions for Qt
*/

View File

@ -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

View File

@ -2579,11 +2579,6 @@ void Configure::autoDetection()
i.value() = defaultTo(i.key());
}
if (tryCompileProject("unix/ptrsize"))
dictionary["QT_POINTER_SIZE"] = "8";
else
dictionary["QT_POINTER_SIZE"] = "4";
cout << "Done running configuration tests." << endl;
}
@ -3762,8 +3757,6 @@ void Configure::generateConfigfiles()
if (dictionary["REDUCE_RELOCATIONS"] == "yes") qconfigList += "QT_REDUCE_RELOCATIONS";
if (dictionary["QT_GETIFADDRS"] == "no") qconfigList += "QT_NO_GETIFADDRS";
qconfigList += QString("QT_POINTER_SIZE=%1").arg(dictionary["QT_POINTER_SIZE"]);
qconfigList.sort();
for (int i = 0; i < qconfigList.count(); ++i)
tmpStream << addDefine(qconfigList.at(i));