From d99800dcacc0c3e09f7d98321e12257ef55b98da Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 20 Dec 2021 21:36:12 +0100 Subject: [PATCH] Make sure that QCocoaWindowManager is initialized in static builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If code has no external references, then with a static build of Qt the linker is free to strip those object files from the final executable. This is what happened with QCocoaWindowManager, which had no exported symbols, and no callers from other files. To prevent the linker from stripping the object file and to ensure that the constructor function gets called during startup, move that function declaration to the QCocoaIntegration code, which is always loaded. Fixes: QTBUG-99280 Pick-to: 6.2 6.3 Change-Id: Icdafea372a1b42c6ecdb43e36aeb0a04a70e3d4e Reviewed-by: Timur Pocheptsov Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoaintegration.mm | 6 ++++++ src/plugins/platforms/cocoa/qcocoawindowmanager.mm | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index b8954509b9..92edeac558 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -57,6 +57,7 @@ #if QT_CONFIG(sessionmanager) # include "qcocoasessionmanager.h" #endif +#include "qcocoawindowmanager.h" #include #include @@ -81,6 +82,11 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcQpa, "qt.qpa", QtWarningMsg); +// Lives here so that the linker is forced to include the QCocoaWindowManager +// object file also in static builds. +static void initializeWindowManager() { Q_UNUSED(QCocoaWindowManager::instance()); } +Q_CONSTRUCTOR_FUNCTION(initializeWindowManager) + static void logVersionInformation() { if (!lcQpa().isInfoEnabled()) diff --git a/src/plugins/platforms/cocoa/qcocoawindowmanager.mm b/src/plugins/platforms/cocoa/qcocoawindowmanager.mm index bb72fea5e6..71bcecdbc6 100644 --- a/src/plugins/platforms/cocoa/qcocoawindowmanager.mm +++ b/src/plugins/platforms/cocoa/qcocoawindowmanager.mm @@ -116,8 +116,5 @@ void QCocoaWindowManager::modalSessionChanged() } } -static void initializeWindowManager() { Q_UNUSED(QCocoaWindowManager::instance()); } -Q_CONSTRUCTOR_FUNCTION(initializeWindowManager) - QT_END_NAMESPACE