From 2398e225abdea36321670d34a8238b6e64dba281 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 8 Sep 2015 20:35:33 -0300 Subject: Auto-detect whether 64-bit std::atomic really works The C++ standard says it must, but some badly-configured toolchains seem to be lacking support. In particular, for some 32-bit platforms without native support for them, GCC implements 64-bit atomics via out-of-line functions in libatomic. If that library is missing... well, then std::atomic 64-bit doesn't work and we mustn't try to use it. This was found when trying to compile Qt 5.6 for MIPS 32-bit: Linking library libQt5Core.so.5.6.0 .obj/qsimd.o: In function `std::__atomic_base::load(std::memory_order) const': /opt/poky/1.7/sysroots/mips32r2-poky-linux/usr/include/c++/4.9.1/bits/atomic_base.h:500: undefined reference to `__atomic_load_8' .obj/qsimd.o: In function `std::__atomic_base::store(unsigned long long, std::memory_order)': /opt/poky/1.7/sysroots/mips32r2-poky-linux/usr/include/c++/4.9.1/bits/atomic_base.h:478: undefined reference to `__atomic_store_8' Yocto bug report: https://bugzilla.yoctoproject.org/show_bug.cgi?id=8274 Change-Id: I42e7ef1a481840699a8dffff140224d6614e5c36 Reviewed-by: Oswald Buddenhagen Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira (cherry picked from commit 3d7586b760550b7d89594c8d7462fc30b868ecc6) Reviewed-by: Dmitry Shachnev --- config.tests/common/atomic64/atomic64.cpp | 54 +++++++++++++++++++++++++++++++ config.tests/common/atomic64/atomic64.pro | 3 ++ 2 files changed, 57 insertions(+) create mode 100644 config.tests/common/atomic64/atomic64.cpp create mode 100644 config.tests/common/atomic64/atomic64.pro (limited to 'config.tests') diff --git a/config.tests/common/atomic64/atomic64.cpp b/config.tests/common/atomic64/atomic64.cpp new file mode 100644 index 0000000000..8dbea96c8b --- /dev/null +++ b/config.tests/common/atomic64/atomic64.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Intel Corporation. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the FOO module 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$ +** +****************************************************************************/ + +#include +#include + +void test(volatile std::atomic &a) +{ + std::int64_t v = a.load(std::memory_order_acquire); + while (!a.compare_exchange_strong(v, v + 1, + std::memory_order_acq_rel, + std::memory_order_acquire)) { + v = a.exchange(v - 1); + } + + a.store(v + 1, std::memory_order_release); +} + +int main(int, char **) +{ + void *ptr = (void*)0xffffffc0; // any random pointer + test(*reinterpret_cast *>(ptr)); + return 0; +} diff --git a/config.tests/common/atomic64/atomic64.pro b/config.tests/common/atomic64/atomic64.pro new file mode 100644 index 0000000000..c9a85817ca --- /dev/null +++ b/config.tests/common/atomic64/atomic64.pro @@ -0,0 +1,3 @@ +SOURCES = atomic64.cpp +CONFIG += c++11 console +CONFIG -= qt -- cgit v1.2.3 From f0d0192652019ed2842741196bf3ace870e09429 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 16 Nov 2015 10:12:24 -0800 Subject: Remove "FOO module" from config.tests/common Change-Id: I14839ba5678944c2864bffff1417413f16d4ffeb Reviewed-by: Oswald Buddenhagen --- config.tests/common/atomic64/atomic64.cpp | 2 +- config.tests/common/c++11/c++11.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'config.tests') diff --git a/config.tests/common/atomic64/atomic64.cpp b/config.tests/common/atomic64/atomic64.cpp index 8dbea96c8b..20fbeca740 100644 --- a/config.tests/common/atomic64/atomic64.cpp +++ b/config.tests/common/atomic64/atomic64.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2015 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the configuration of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage diff --git a/config.tests/common/c++11/c++11.cpp b/config.tests/common/c++11/c++11.cpp index 30934951d7..2560113c3f 100644 --- a/config.tests/common/c++11/c++11.cpp +++ b/config.tests/common/c++11/c++11.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2015 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the configuration of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage -- cgit v1.2.3