From 41b2c4204bd965532b5a79a44d6b0ad6727d3683 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 3 Mar 2022 08:45:11 -0800 Subject: [PATCH] Q_DECL_INIT_PRIORITY: make the initializers actually run The runtime runs the function pointers located between subsections $XCA and $XCZ only, so using $QT meant it would never get run. Change-Id: Ibf4acec0f166495998f7fffd16d8ecb19019ce10 Reviewed-by: Allan Sandfeld Jensen --- src/corelib/global/qglobal_p.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/qglobal_p.h b/src/corelib/global/qglobal_p.h index e22c5b11eef..f49a66df833 100644 --- a/src/corelib/global/qglobal_p.h +++ b/src/corelib/global/qglobal_p.h @@ -61,11 +61,16 @@ #endif #if defined(Q_CC_MSVC) +// By default, dynamic initialization uses subsection "$XCU", which is +// equivalent to #pragma init_seg(user). Additionally, #pragma +// init_seg(compiler) and init_seg(lib) use "$XCC" and "$XCL" respectively. So +// place us between "compiler" and "lib". # define QT_SUPPORTS_INIT_PRIORITY 1 + // warning C4075: initializers put in unrecognized initialization area # define Q_DECL_INIT_PRIORITY(nn) \ __pragma(warning(disable: 4075)) \ - __pragma(init_seg(".CRT$QT" QT_STRINGIFY(nn))) Q_DECL_UNUSED + __pragma(init_seg(".CRT$XCK" QT_STRINGIFY(nn))) Q_DECL_UNUSED #elif defined(Q_OS_WIN) || defined(Q_OF_ELF) # define QT_SUPPORTS_INIT_PRIORITY 1 // priorities 0 to 1000 are reserved to the runtime;