1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Intel Corporation.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 // qglobal.h includes this header, so keep it outside of our include guards
41 #include <QtCore/qglobal.h>
42 
43 #if !defined(QVERSIONTAGGING_H)
44 #define QVERSIONTAGGING_H
45 
46 QT_BEGIN_NAMESPACE
47 
48 /*
49  * Ugly hack warning and explanation:
50  *
51  * This file causes all ELF modules, be they libraries or applications, to use the
52  * qt_version_tag symbol that is present in QtCore. Such symbol is versioned,
53  * so the linker will automatically pull the current Qt version and add it to
54  * the ELF header of the library/application. The assembly produces one section
55  * called ".qtversion" containing two 32-bit values. The first is a
56  * relocation to the qt_version_tag symbol (which is what causes the ELF
57  * version to get used). The second value is the current Qt version at the time
58  * of compilation.
59  *
60  * There will only be one copy of the section in the output library or application.
61  */
62 
63 #if defined(QT_BUILD_CORE_LIB) || defined(QT_BOOTSTRAPPED) || defined(QT_NO_VERSION_TAGGING) || defined(QT_STATIC)
64 // don't make tags in QtCore, bootstrapped systems or if the user asked not to
65 #elif defined(Q_CC_GNU) && !defined(Q_OS_ANDROID)
66 #  if defined(Q_PROCESSOR_X86) && (defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD_KERNEL))
67 #    if defined(Q_PROCESSOR_X86_64) && QT_POINTER_SIZE == 8     // x86-64 64-bit
68 #      define QT_VERSION_TAG_RELOC(sym) ".quad " QT_STRINGIFY(QT_MANGLE_NAMESPACE(sym)) "@GOT\n"
69 #    else                                                       // x86 or x86-64 32-bit (x32)
70 #      define QT_VERSION_TAG_RELOC(sym) ".long " QT_STRINGIFY(QT_MANGLE_NAMESPACE(sym)) "@GOT\n"
71 #    endif
72 #    define QT_VERSION_TAG(sym) \
73     asm (   \
74     ".section .qtversion, \"aG\", @progbits, " QT_STRINGIFY(QT_MANGLE_NAMESPACE(sym)) ", comdat\n" \
75     ".align 8\n" \
76     QT_VERSION_TAG_RELOC(sym) \
77     ".long " QT_STRINGIFY(QT_VERSION) "\n" \
78     ".align 8\n" \
79     ".previous" \
80     )
81 #  endif
82 #endif
83 
84 #if defined(QT_VERSION_TAG)
85 QT_VERSION_TAG(qt_version_tag);
86 #endif
87 
88 QT_END_NAMESPACE
89 
90 #endif // QVERSIONTAGGING_H
91