Avoid GHS linker to optimize away QML type registrations

GHS linker optimizes away QML type registrations despite volatile.
To prevent this we add #pragma ghs reference(s) to avoid such linker
optimization.

Task-number: QTBUG-94846
Pick-to: 6.2
Change-Id: I6ae2d350e532d2035c300a024cb000014293e1a0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Tatiana Borisova 2021-07-22 19:57:34 +03:00
parent 1ff3785348
commit 682f783937
4 changed files with 13 additions and 1 deletions

View File

@ -975,7 +975,7 @@ function(qt6_add_qml_plugin target)
# These are all substituted in the template file used further below
set(qt_qml_plugin_class_name "${arg_CLASS_NAME}")
set(qt_qml_plugin_moc_include_name "${generated_cpp_file_name_base}.moc")
set(qt_qml_plugin_intro "extern void ${register_types_function_name}();")
set(qt_qml_plugin_intro "extern void ${register_types_function_name}();\nQ_GHS_KEEP_REFERENCE(${register_types_function_name});")
set(qt_qml_plugin_outro "")
if(QT_BUILDING_QT)
string(APPEND qt_qml_plugin_intro "\n\nQT_BEGIN_NAMESPACE")

View File

@ -44,6 +44,12 @@
#include <QtCore/QUrl>
#include <QtQml/qqmlextensioninterface.h>
#if defined(Q_CC_GHS)
# define Q_GHS_KEEP_REFERENCE(S) QT_DO_PRAGMA(ghs reference S ##__Fv)
#else
# define Q_GHS_KEEP_REFERENCE(S)
#endif
#define Q_IMPORT_QML_PLUGIN(PLUGIN) \
Q_IMPORT_PLUGIN(PLUGIN)

View File

@ -42,6 +42,9 @@
QT_BEGIN_NAMESPACE
Q_GHS_KEEP_REFERENCE(qml_register_types_QtQuick);
Q_GHS_KEEP_REFERENCE(QQuick_initializeModule);
class QtQuick2Plugin : public QQmlEngineExtensionPlugin
{
Q_OBJECT

View File

@ -41,6 +41,9 @@
#include <QtQml/qqml.h>
#include <QtQuickShapes/private/qquickshape_p.h>
Q_GHS_KEEP_REFERENCE(qml_register_types_QtQuick_Shapes);
Q_GHS_KEEP_REFERENCE(QQuickShapes_initializeModule);
QT_BEGIN_NAMESPACE
class QmlShapesPlugin : public QQmlEngineExtensionPlugin