Update qversiontagging.cpp not to use too much assembler magic

The only reason I had used them in the first place was because C
preprocessor macros cannot call themselves recursively. But the magic
was too magic and caused issues with some builds, so let's choose the
safer option.

Anyway, this solution now works for all ELF architectures, independent
of the processor, whereas previously it was restricted to x86 and Linux/
FreeBSD. However, this does not apply to the assembly in
qversiontagging.h.

Change-Id: I42e7ef1a481840699a8dffff1404f032fc5cacb8
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
bb10
Thiago Macieira 2015-09-17 19:04:42 -07:00
parent 2538b53340
commit 629ceec208
3 changed files with 57 additions and 60 deletions

View File

@ -196,10 +196,14 @@ unix:!isEmpty(QMAKE_LFLAGS_VERSION_SCRIPT):!no_linker_version_script:!static {
} else {
current = Qt_$$QT_MAJOR_VERSION
verscript_content = "$$current { *; };"
for(i, 0..$$section(VERSION, ., 1, 1)) {
isEmpty(QT_NAMESPACE): tag_symbol = qt_version_tag
else: tag_symbol = qt_version_tag_$$QT_NAMESPACE
for(i, 0..$$QT_MINOR_VERSION) {
previous = $$current
current = Qt_$${QT_MAJOR_VERSION}.$$i
verscript_content += "$$current {} $$previous;"
equals(i, $$QT_MINOR_VERSION): verscript_content += "$$current { $$tag_symbol; } $$previous;"
else: verscript_content += "$$current {} $$previous;"
}
}
write_file($$verscript, verscript_content)|error("Aborting.")

View File

@ -27,7 +27,8 @@ SOURCES += \
global/qmalloc.cpp \
global/qnumeric.cpp \
global/qlogging.cpp \
global/qhooks.cpp
global/qhooks.cpp \
global/qversiontagging.cpp
# qlibraryinfo.cpp includes qconfig.cpp
INCLUDEPATH += $$QT_BUILD_TREE/src/corelib/global
@ -58,28 +59,3 @@ journald {
syslog {
DEFINES += QT_USE_SYSLOG
}
linux|freebsd {
VERSIONTAGGING_SOURCES = global/qversiontagging.cpp
ltcg|clang {
versiontagging_compiler.commands = $$QMAKE_CXX -c $(CXXFLAGS) $(INCPATH)
# Disable LTO, as the global inline assembly may not get processed
versiontagging_compiler.commands += -fno-lto
# Disable the integrated assembler for Clang, since it can't parse with
# the alternate macro syntax in use in qversiontagging.cpp
clang: versiontagging_compiler.commands += -no-integrated-as
versiontagging_compiler.commands += -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
versiontagging_compiler.dependency_type = TYPE_C
versiontagging_compiler.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_BASE}$${first(QMAKE_EXT_OBJ)}
versiontagging_compiler.input = VERSIONTAGGING_SOURCES
versiontagging_compiler.variable_out = OBJECTS
versiontagging_compiler.name = compiling[versiontagging] ${QMAKE_FILE_IN}
silent: versiontagging_compiler.commands = @echo compiling[versiontagging] ${QMAKE_FILE_IN} && $$versiontagging_compiler.commands
QMAKE_EXTRA_COMPILERS += versiontagging_compiler
} else {
SOURCES += $$VERSIONTAGGING_SOURCES
}
}

View File

@ -33,37 +33,54 @@
#include "qglobal.h"
#if defined(Q_CC_GNU) && (defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)) && defined(Q_PROCESSOR_X86) && !defined(QT_STATIC)
# define SYM QT_MANGLE_NAMESPACE(qt_version_tag)
# define SSYM QT_STRINGIFY(SYM)
asm(
// ASM macro that makes one ELF versioned symbol
".macro make_versioned_symbol plainsym versionedsym\n"
".globl plainsym\n"
".type plainsym, @object\n"
".size plainsym, 1\n"
".symver plainsym, versionedsym\n"
"plainsym :\n"
".endm\n"
// ASM macro that makes one ELF versioned symbol qt_version_tag{sep}Qt_{major}.{minor}
// that is an alias to qt_version_tag_{major}_{minor}.
// The {sep} parameter must be @ for all old versions and @@ for the current version.
".macro make_one_tag major minor sep\n"
" make_versioned_symbol " SSYM "_\\major\\()_\\minor, " SSYM "\\sep\\()Qt_\\major\\().\\minor\n"
".endm\n"
".altmacro\n"
".bss\n"
".set qt_version_major, " QT_STRINGIFY(QT_VERSION) " >> 16\n" // set qt_version_major
".set qt_version_minor, 0\n" // set qt_version_minor to 0 (it will grow to the current)
".rept (" QT_STRINGIFY(QT_VERSION) " >> 8) & 0xff\n" // repeat minor version times (0 to N-1)
" make_one_tag %qt_version_major, %qt_version_minor, @\n"
" .set qt_version_minor, (qt_version_minor + 1)\n"
".endr\n"
" make_one_tag %qt_version_major, %qt_version_minor, @@\n" // call the macro for the current version
" .space 1\n" // variable is 1 byte, value 0
);
#define SYM QT_MANGLE_NAMESPACE(qt_version_tag)
//#define SSYM QT_STRINGIFY(SYM)
#if defined(Q_CC_GNU) && defined(Q_OF_ELF)
# define make_versioned_symbol2(sym, m, n, separator) \
Q_CORE_EXPORT extern const char sym ## _ ## m ## _ ## n = 0; \
asm(".symver " QT_STRINGIFY(sym) "_" QT_STRINGIFY(m) "_" QT_STRINGIFY(n) ", " \
QT_STRINGIFY(sym) separator "Qt_" QT_STRINGIFY(m) "." QT_STRINGIFY(n))
#else
# define make_versioned_symbol2(sym, m, n, separator)
#endif
#define make_versioned_symbol(sym, m, n, separator) make_versioned_symbol2(sym, m, n, separator)
extern "C" {
#if QT_VERSION_MINOR > 0
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 0, "@");
#endif
#if QT_VERSION_MINOR > 1
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 1, "@");
#endif
#if QT_VERSION_MINOR > 2
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 2, "@");
#endif
#if QT_VERSION_MINOR > 3
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 3, "@");
#endif
#if QT_VERSION_MINOR > 4
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 4, "@");
#endif
#if QT_VERSION_MINOR > 5
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 5, "@");
#endif
#if QT_VERSION_MINOR > 6
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 6, "@");
#endif
#if QT_VERSION_MINOR > 7
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 7, "@");
#endif
#if QT_VERSION_MINOR > 8
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 8, "@");
#endif
#if QT_VERSION_MINOR > 9
make_versioned_symbol(SYM, QT_VERSION_MAJOR, 9, "@");
#endif
#if QT_VERSION_MINOR > 10
# error "Please update this file with more Qt versions."
#endif
// the default version:
make_versioned_symbol(SYM, QT_VERSION_MAJOR, QT_VERSION_MINOR, "@@");
}