diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-01-31 16:05:52 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-02-04 11:07:15 +0100 |
commit | ac46c9f6ce9ef757e0ccba8a283cb0efabaef56e (patch) | |
tree | 9c2768c78fb5cc37024d5518115f1b7998f5f72b /src | |
parent | 6e111f96e307501ec02a620fa3124fd3ce9c9193 (diff) |
Synthetically reference type registration functions
Add unused volatile pointers to the type registration functions in each
import plugin. We need to do this in order to prevent the linker from
optimizing the registration away. There are two ways for this to happen:
When linking statically, the linker will examine the referenced symbols
on a per-object base and leave out all unreferenced objects. When
linking dynamically, the linker may do the same on a per-library base
and drop any unreferenced libraries from the dependencies. Forcing a
reference to the type registration function prevents both.
The volatile technique allows us to remove the previous qCDebug() hack.
Having an unused volatile auto variable should only result in a single
memory read as runtime overhead. The qCDebug() technique would generate
a read and a block of mostly dead code (as no one would ever use that
logging category).
Fixes: QTBUG-81622
Change-Id: I255667276dfd355b19baa17b1aad3db406bf1954
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
24 files changed, 113 insertions, 44 deletions
diff --git a/src/imports/folderlistmodel/plugin.cpp b/src/imports/folderlistmodel/plugin.cpp index 28837655ef..7a38769b77 100644 --- a/src/imports/folderlistmodel/plugin.cpp +++ b/src/imports/folderlistmodel/plugin.cpp @@ -42,6 +42,8 @@ #include "qquickfolderlistmodel.h" +extern void qml_register_types_Qt_labs_folderlistmodel(); + QT_BEGIN_NAMESPACE //![class decl] @@ -51,7 +53,12 @@ class QmlFolderListModelPlugin : public QQmlExtensionPlugin Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) public: - QmlFolderListModelPlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) { } + QmlFolderListModelPlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_Qt_labs_folderlistmodel; + Q_UNUSED(registration); + } + void registerTypes(const char *uri) override { Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.folderlistmodel")); diff --git a/src/imports/labsanimation/plugin.cpp b/src/imports/labsanimation/plugin.cpp index bd732a6aba..9c985f0dcf 100644 --- a/src/imports/labsanimation/plugin.cpp +++ b/src/imports/labsanimation/plugin.cpp @@ -42,6 +42,8 @@ #include "qquickboundaryrule_p.h" +extern void qml_register_types_Qt_labs_animation(); + QT_BEGIN_NAMESPACE /*! @@ -66,7 +68,11 @@ class QtLabsAnimationPlugin : public QQmlEngineExtensionPlugin Q_OBJECT Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - QtLabsAnimationPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { } + QtLabsAnimationPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_Qt_labs_animation; + Q_UNUSED(registration); + } }; //![class decl] diff --git a/src/imports/labsmodels/plugin.cpp b/src/imports/labsmodels/plugin.cpp index feb4f3ba0a..ab5e0023a6 100644 --- a/src/imports/labsmodels/plugin.cpp +++ b/src/imports/labsmodels/plugin.cpp @@ -50,6 +50,8 @@ #include "qqmldelegatecomponent_p.h" #endif +extern void qml_register_types_Qt_labs_qmlmodels(); + QT_BEGIN_NAMESPACE /*! @@ -74,7 +76,11 @@ class QtQmlLabsModelsPlugin : public QQmlEngineExtensionPlugin Q_OBJECT Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - QtQmlLabsModelsPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { } + QtQmlLabsModelsPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_Qt_labs_qmlmodels; + Q_UNUSED(registration); + } }; //![class decl] diff --git a/src/imports/layouts/plugin.cpp b/src/imports/layouts/plugin.cpp index c302b79164..af270c1732 100644 --- a/src/imports/layouts/plugin.cpp +++ b/src/imports/layouts/plugin.cpp @@ -42,6 +42,8 @@ #include "qquicklinearlayout_p.h" #include "qquickstacklayout_p.h" +extern void qml_register_types_QtQuick_Layouts(); + QT_BEGIN_NAMESPACE //![class decl] @@ -52,6 +54,8 @@ class QtQuickLayoutsPlugin : public QQmlEngineExtensionPlugin public: QtQuickLayoutsPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { + volatile auto registration = &qml_register_types_QtQuick_Layouts; + Q_UNUSED(registration); } }; //![class decl] diff --git a/src/imports/localstorage/plugin.cpp b/src/imports/localstorage/plugin.cpp index ae9f37784d..e488b3d43c 100644 --- a/src/imports/localstorage/plugin.cpp +++ b/src/imports/localstorage/plugin.cpp @@ -42,6 +42,8 @@ #include <QtQml/qqmlextensionplugin.h> #include <QtQml/qqml.h> +extern void qml_register_types_QtQuick_LocalStorage(); + QT_BEGIN_NAMESPACE class QQmlLocalStoragePlugin : public QQmlEngineExtensionPlugin @@ -52,6 +54,8 @@ class QQmlLocalStoragePlugin : public QQmlEngineExtensionPlugin public: QQmlLocalStoragePlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { + volatile auto registration = &qml_register_types_QtQuick_LocalStorage; + Q_UNUSED(registration); } }; diff --git a/src/imports/models/plugin.cpp b/src/imports/models/plugin.cpp index 4aa9f27766..c15866cf05 100644 --- a/src/imports/models/plugin.cpp +++ b/src/imports/models/plugin.cpp @@ -37,17 +37,11 @@ ** ****************************************************************************/ -#include <QtQmlModels/private/qqmlobjectmodel_p.h> - +#include <QtQmlModels/private/qtqmlmodelsglobal_p.h> #include <QtQml/qqmlextensionplugin.h> -#include <QtQml/qqml.h> - -#include <QtCore/qloggingcategory.h> QT_BEGIN_NAMESPACE -Q_LOGGING_CATEGORY(qmlModelsPlugin, "qt.qmlModelsPlugin") - /*! \qmlmodule QtQml.Models 2.\QtMinorVersion \title Qt QML Models QML Types @@ -92,13 +86,8 @@ class QtQmlModelsPlugin : public QQmlEngineExtensionPlugin public: QtQmlModelsPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { - if (qmlModelsPlugin().isDebugEnabled()) { - // Superficial debug message that causes the dependency between QtQmlWorkerScript - // and the workerscript plugin to be retained. - // As qCDebug() can be a noop, retrieve the className in a separate step. - const QString className = QQmlObjectModel::staticMetaObject.className(); - qCDebug(qmlModelsPlugin) << "Loading QmlModels plugin:" << className; - } + volatile auto registration = &qml_register_types_QtQml_Models; + Q_UNUSED(registration); } }; //![class decl] diff --git a/src/imports/particles/plugin.cpp b/src/imports/particles/plugin.cpp index 4f319db9f1..6629a660af 100644 --- a/src/imports/particles/plugin.cpp +++ b/src/imports/particles/plugin.cpp @@ -50,7 +50,12 @@ class QtQuick2ParticlesPlugin : public QQmlExtensionPlugin Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) public: - QtQuick2ParticlesPlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) { } + QtQuick2ParticlesPlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_QtQuick_Particles; + Q_UNUSED(registration); + } + void registerTypes(const char *uri) override { Q_UNUSED(uri); diff --git a/src/imports/qtqml/plugin.cpp b/src/imports/qtqml/plugin.cpp index 6891755446..854ef6d2e6 100644 --- a/src/imports/qtqml/plugin.cpp +++ b/src/imports/qtqml/plugin.cpp @@ -37,10 +37,8 @@ ** ****************************************************************************/ +#include <QtQml/private/qtqmlglobal_p.h> #include <QtQml/qqmlextensionplugin.h> -#include <QtQml/private/qqmlengine_p.h> -#include <QtQml/private/qqmlcomponentattached_p.h> -#include <QtQml/private/qqmlbind_p.h> #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include <QtQmlModels/private/qqmlmodelsmodule_p.h> @@ -71,7 +69,12 @@ class QtQmlPlugin : public QQmlExtensionPlugin Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) public: - QtQmlPlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) { } + QtQmlPlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_QtQml; + Q_UNUSED(registration); + } + void registerTypes(const char *) override { QQmlModelsModule::registerQmlTypes(); } }; #else @@ -80,7 +83,11 @@ class QtQmlPlugin : public QQmlEngineExtensionPlugin Q_OBJECT Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - QtQmlPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) {} + QtQmlPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_QtQml; + Q_UNUSED(registration); + } }; #endif //![class decl] diff --git a/src/imports/qtquick2/plugin.cpp b/src/imports/qtquick2/plugin.cpp index 0832e22e5d..20bc4a3cc0 100644 --- a/src/imports/qtquick2/plugin.cpp +++ b/src/imports/qtquick2/plugin.cpp @@ -57,7 +57,12 @@ class QtQuick2Plugin : public QQmlExtensionPlugin Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) public: - QtQuick2Plugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) { } + QtQuick2Plugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_QtQuick; + Q_UNUSED(registration); + } + void registerTypes(const char *uri) override { Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick")); diff --git a/src/imports/settings/plugin.cpp b/src/imports/settings/plugin.cpp index 24ff43ea6f..e8e640412b 100644 --- a/src/imports/settings/plugin.cpp +++ b/src/imports/settings/plugin.cpp @@ -42,6 +42,8 @@ #include "qqmlsettings_p.h" +extern void qml_register_types_Qt_labs_settings(); + QT_BEGIN_NAMESPACE class QmlSettingsPlugin : public QQmlEngineExtensionPlugin @@ -50,7 +52,11 @@ class QmlSettingsPlugin : public QQmlEngineExtensionPlugin Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - QmlSettingsPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) {} + QmlSettingsPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_Qt_labs_settings; + Q_UNUSED(registration); + } }; QT_END_NAMESPACE diff --git a/src/imports/shapes/plugin.cpp b/src/imports/shapes/plugin.cpp index 3855a93fc7..48eecbd8f1 100644 --- a/src/imports/shapes/plugin.cpp +++ b/src/imports/shapes/plugin.cpp @@ -52,6 +52,8 @@ public: QmlShapesPlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) { + volatile auto registration = &qml_register_types_QtQuick_Shapes; + Q_UNUSED(registration); } void registerTypes(const char *uri) override diff --git a/src/imports/sharedimage/plugin.cpp b/src/imports/sharedimage/plugin.cpp index 237fa64c61..d7c2ef8d17 100644 --- a/src/imports/sharedimage/plugin.cpp +++ b/src/imports/sharedimage/plugin.cpp @@ -99,6 +99,8 @@ The shared image module does not provide any directly usable QML types. */ +extern void qml_register_types_Qt_labs_sharedimage(); + QT_BEGIN_NAMESPACE class QtQuickSharedImagePlugin : public QQmlEngineExtensionPlugin @@ -106,7 +108,11 @@ class QtQuickSharedImagePlugin : public QQmlEngineExtensionPlugin Q_OBJECT Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - QtQuickSharedImagePlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) {} + QtQuickSharedImagePlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_Qt_labs_sharedimage; + Q_UNUSED(registration); + } void initializeEngine(QQmlEngine *engine, const char *uri) override { diff --git a/src/imports/statemachine/plugin.cpp b/src/imports/statemachine/plugin.cpp index 4c991994f3..c370504029 100644 --- a/src/imports/statemachine/plugin.cpp +++ b/src/imports/statemachine/plugin.cpp @@ -48,6 +48,8 @@ #include <QQmlExtensionPlugin> #include <qqml.h> +extern void qml_register_types_QtQml_StateMachine(); + QT_BEGIN_NAMESPACE class QtQmlStateMachinePlugin : public QQmlEngineExtensionPlugin @@ -56,7 +58,11 @@ class QtQmlStateMachinePlugin : public QQmlEngineExtensionPlugin Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - QtQmlStateMachinePlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { } + QtQmlStateMachinePlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_QtQml_StateMachine; + Q_UNUSED(registration); + } }; QT_END_NAMESPACE diff --git a/src/imports/testlib/main.cpp b/src/imports/testlib/main.cpp index 1914c02dd0..83fc150e6c 100644 --- a/src/imports/testlib/main.cpp +++ b/src/imports/testlib/main.cpp @@ -50,6 +50,8 @@ QML_DECLARE_TYPE(QuickTestResult) QML_DECLARE_TYPE(QuickTestEvent) QML_DECLARE_TYPE(QuickTestUtil) +extern void qml_register_types_QtTest(); + QT_BEGIN_NAMESPACE class QTestQmlModule : public QQmlEngineExtensionPlugin @@ -58,7 +60,11 @@ class QTestQmlModule : public QQmlEngineExtensionPlugin Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - QTestQmlModule(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { } + QTestQmlModule(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_QtTest; + Q_UNUSED(registration); + } }; QT_END_NAMESPACE diff --git a/src/imports/wavefrontmesh/plugin.cpp b/src/imports/wavefrontmesh/plugin.cpp index 9bb7a45b2f..eea0db19db 100644 --- a/src/imports/wavefrontmesh/plugin.cpp +++ b/src/imports/wavefrontmesh/plugin.cpp @@ -42,6 +42,8 @@ #include "qwavefrontmesh.h" +extern void qml_register_types_Qt_labs_wavefrontmesh(); + QT_BEGIN_NAMESPACE class QmlWavefrontMeshPlugin : public QQmlEngineExtensionPlugin @@ -52,6 +54,8 @@ public: QmlWavefrontMeshPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { + volatile auto registration = &qml_register_types_Qt_labs_wavefrontmesh; + Q_UNUSED(registration); } }; diff --git a/src/imports/window/plugin.cpp b/src/imports/window/plugin.cpp index ec4f2c5d2a..5152fa02ec 100644 --- a/src/imports/window/plugin.cpp +++ b/src/imports/window/plugin.cpp @@ -41,6 +41,8 @@ #include "plugin.h" +extern void qml_register_types_QtQuick_Window(); + QT_BEGIN_NAMESPACE /*! @@ -64,7 +66,11 @@ class QtQuick2WindowPlugin : public QQmlEngineExtensionPlugin Q_OBJECT Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - QtQuick2WindowPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { } + QtQuick2WindowPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) + { + volatile auto registration = &qml_register_types_QtQuick_Window; + Q_UNUSED(registration); + } }; //![class decl] diff --git a/src/imports/workerscript/plugin.cpp b/src/imports/workerscript/plugin.cpp index 0961979c53..1323b17ef4 100644 --- a/src/imports/workerscript/plugin.cpp +++ b/src/imports/workerscript/plugin.cpp @@ -37,17 +37,11 @@ ** ****************************************************************************/ -#include <QtQmlWorkerScript/private/qquickworkerscript_p.h> - +#include <QtQmlWorkerScript/private/qtqmlworkerscriptglobal_p.h> #include <QtQml/qqmlextensionplugin.h> -#include <QtQml/qqml.h> - -#include <QtCore/qloggingcategory.h> QT_BEGIN_NAMESPACE -Q_LOGGING_CATEGORY(workerScriptPlugin, "qt.workerScriptPlugin") - /*! \qmlmodule QtQml.WorkerScript 2.\QtMinorVersion \title Qt QML WorkerScript QML Types @@ -71,13 +65,8 @@ class QtQmlWorkerScriptPlugin : public QQmlEngineExtensionPlugin public: QtQmlWorkerScriptPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) { - if (workerScriptPlugin().isDebugEnabled()) { - // Superficial debug message that causes the dependency between QtQmlWorkerScript - // and the workerscript plugin to be retained. - // As qCDebug() can be a noop, retrieve the className in a separate step. - const QString className = QQuickWorkerScript::staticMetaObject.className(); - qCDebug(workerScriptPlugin) << "Loading WorkerScript plugin:" << className; - } + volatile auto registration = &qml_register_types_QtQml_WorkerScript; + Q_UNUSED(registration); } }; diff --git a/src/particles/qtquickparticlesglobal_p.h b/src/particles/qtquickparticlesglobal_p.h index d7647b3d97..927bc29050 100644 --- a/src/particles/qtquickparticlesglobal_p.h +++ b/src/particles/qtquickparticlesglobal_p.h @@ -65,4 +65,6 @@ # define Q_QUICKPARTICLES_PRIVATE_EXPORT #endif +void Q_QUICKPARTICLES_PRIVATE_EXPORT qml_register_types_QtQuick_Particles(); + #endif // QTQUICKPARTICLESGLOBAL_P_H diff --git a/src/qml/qtqmlglobal_p.h b/src/qml/qtqmlglobal_p.h index 9ca0cf2abe..a729729b67 100644 --- a/src/qml/qtqmlglobal_p.h +++ b/src/qml/qtqmlglobal_p.h @@ -60,6 +60,8 @@ #define Q_QML_PRIVATE_EXPORT Q_QML_EXPORT +void Q_QML_PRIVATE_EXPORT qml_register_types_QtQml(); + #if !defined(QT_QMLDEVTOOLS_LIB) && !defined(QT_BUILD_QMLDEVTOOLS_LIB) # define Q_QML_AUTOTEST_EXPORT Q_AUTOTEST_EXPORT #else diff --git a/src/qmlmodels/qtqmlmodelsglobal_p.h b/src/qmlmodels/qtqmlmodelsglobal_p.h index 145112c9c1..1a1157138d 100644 --- a/src/qmlmodels/qtqmlmodelsglobal_p.h +++ b/src/qmlmodels/qtqmlmodelsglobal_p.h @@ -58,4 +58,6 @@ #define Q_QMLMODELS_PRIVATE_EXPORT Q_QMLMODELS_EXPORT #define Q_QMLMODELS_AUTOTEST_EXPORT Q_AUTOTEST_EXPORT +void Q_QMLMODELS_PRIVATE_EXPORT qml_register_types_QtQml_Models(); + #endif // QTQMLMODELSGLOBAL_P_H diff --git a/src/qmlworkerscript/qquickworkerscript_p.h b/src/qmlworkerscript/qquickworkerscript_p.h index 03581089e0..22a205cfe4 100644 --- a/src/qmlworkerscript/qquickworkerscript_p.h +++ b/src/qmlworkerscript/qquickworkerscript_p.h @@ -84,7 +84,7 @@ private: }; class QQmlV4Function; -class Q_QMLWORKERSCRIPT_PRIVATE_EXPORT QQuickWorkerScript : public QObject, public QQmlParserStatus +class Q_AUTOTEST_EXPORT QQuickWorkerScript : public QObject, public QQmlParserStatus { Q_OBJECT Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) diff --git a/src/qmlworkerscript/qtqmlworkerscriptglobal_p.h b/src/qmlworkerscript/qtqmlworkerscriptglobal_p.h index 34236cd79e..c75d5f3129 100644 --- a/src/qmlworkerscript/qtqmlworkerscriptglobal_p.h +++ b/src/qmlworkerscript/qtqmlworkerscriptglobal_p.h @@ -57,4 +57,6 @@ #define Q_QMLWORKERSCRIPT_PRIVATE_EXPORT Q_QMLWORKERSCRIPT_EXPORT #define Q_QMLWORKERSCRIPT_AUTOTEST_EXPORT Q_AUTOTEST_EXPORT +void Q_QMLWORKERSCRIPT_PRIVATE_EXPORT qml_register_types_QtQml_WorkerScript(); + #endif // QTQMLWORKERSCRIPTGLOBAL_P_H diff --git a/src/quick/qtquickglobal_p.h b/src/quick/qtquickglobal_p.h index f6376a6d17..80e59563c7 100644 --- a/src/quick/qtquickglobal_p.h +++ b/src/quick/qtquickglobal_p.h @@ -61,6 +61,8 @@ #define Q_QUICK_PRIVATE_EXPORT Q_QUICK_EXPORT +void Q_QUICK_PRIVATE_EXPORT qml_register_types_QtQuick(); + QT_BEGIN_NAMESPACE void QQuick_initializeProviders(); diff --git a/src/quickshapes/qquickshapesglobal_p.h b/src/quickshapes/qquickshapesglobal_p.h index 2f559b45a0..40f6cfbdcf 100644 --- a/src/quickshapes/qquickshapesglobal_p.h +++ b/src/quickshapes/qquickshapesglobal_p.h @@ -59,5 +59,6 @@ QT_BEGIN_NAMESPACE QT_END_NAMESPACE +void Q_QUICKSHAPES_PRIVATE_EXPORT qml_register_types_QtQuick_Shapes(); #endif // QQUICKSHAPESGLOBAL_P_H |