summaryrefslogtreecommitdiff
path: root/libsoup/gconstructor.h
diff options
context:
space:
mode:
authorIgnacio Casal Quinteiro <icq@gnome.org>2015-11-16 12:26:50 +0100
committerIgnacio Casal Quinteiro <icq@gnome.org>2015-11-16 12:26:50 +0100
commit07cf9e7dedb72fdc69b850d7d48b705d2f729e21 (patch)
tree07b9b56d75cf2f257c6c0b0f5f5d625ce16ec830 /libsoup/gconstructor.h
parent693d79e03eb3c86922da2f2f985cc558a9b048f9 (diff)
downloadlibsoup-07cf9e7dedb72fdc69b850d7d48b705d2f729e21.tar.gz
Update gconstructor from glib
Diffstat (limited to 'libsoup/gconstructor.h')
-rw-r--r--libsoup/gconstructor.h38
1 files changed, 32 insertions, 6 deletions
diff --git a/libsoup/gconstructor.h b/libsoup/gconstructor.h
index df98f835..dccb0314 100644
--- a/libsoup/gconstructor.h
+++ b/libsoup/gconstructor.h
@@ -30,17 +30,43 @@
#define G_HAS_CONSTRUCTORS 1
-#define G_DEFINE_CONSTRUCTOR(_func) \
+/* We do some weird things to avoid the constructors being optimized
+ * away on VS2015 if WholeProgramOptimization is enabled. First we
+ * make a reference to the array from the wrapper to make sure its
+ * references. Then we use a pragma to make sure the wrapper function
+ * symbol is always included at the link stage. Also, the symbols
+ * need to be extern (but not dllexport), even though they are not
+ * really used from another object file.
+ */
+
+/* We need to account for differences between the mangling of symbols
+ * for Win32 (x86) and x64 programs, as symbols on Win32 are prefixed
+ * with an underscore but symbols on x64 are not.
+ */
+#ifdef _WIN64
+#define G_MSVC_SYMBOL_PREFIX ""
+#else
+#define G_MSVC_SYMBOL_PREFIX "_"
+#endif
+
+#define G_DEFINE_CONSTRUCTOR(_func) G_MSVC_CTOR (_func, G_MSVC_SYMBOL_PREFIX)
+#define G_DEFINE_DESTRUCTOR(_func) G_MSVC_DTOR (_func, G_MSVC_SYMBOL_PREFIX)
+
+#define G_MSVC_CTOR(_func,_sym_prefix) \
static void _func(void); \
- static int _func ## _wrapper(void) { _func(); return 0; } \
+ extern int (* _array ## _func)(void); \
+ int _func ## _wrapper(void) { _func(); g_slist_find (NULL, _array ## _func); return 0; } \
+ __pragma(comment(linker,"/include:" _sym_prefix # _func "_wrapper")) \
__pragma(section(".CRT$XCU",read)) \
- __declspec(allocate(".CRT$XCU")) static int (* _array ## _func)(void) = _func ## _wrapper;
+ __declspec(allocate(".CRT$XCU")) int (* _array ## _func)(void) = _func ## _wrapper;
-#define G_DEFINE_DESTRUCTOR(_func) \
+#define G_MSVC_DTOR(_func,_sym_prefix) \
static void _func(void); \
- static int _func ## _constructor(void) { atexit (_func); return 0; } \
+ extern int (* _array ## _func)(void); \
+ int _func ## _constructor(void) { atexit (_func); g_slist_find (NULL, _array ## _func); return 0; } \
+ __pragma(comment(linker,"/include:" _sym_prefix # _func "_constructor")) \
__pragma(section(".CRT$XCU",read)) \
- __declspec(allocate(".CRT$XCU")) static int (* _array ## _func)(void) = _func ## _constructor;
+ __declspec(allocate(".CRT$XCU")) int (* _array ## _func)(void) = _func ## _constructor;
#elif defined (_MSC_VER)