After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 678387 - No initialisation when using static version of glib under win32
No initialisation when using static version of glib under win32
Status: RESOLVED DUPLICATE of bug 660731
Product: glib
Classification: Platform
Component: win32
2.33.x
Other Linux
: Normal major
: ---
Assigned To: gtk-win32 maintainers
gtk-win32 maintainers
Depends on:
Blocks:
 
 
Reported: 2012-06-19 10:40 UTC by Andrej
Modified: 2012-10-09 15:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed fix, but with a TODO (so not to be merged as-is, probably). (961 bytes, patch)
2012-06-19 10:40 UTC, Andrej
needs-work Details | Review
glib-init: Fully initialize from constructor when built static on win32 (1.00 KB, patch)
2012-08-17 19:02 UTC, Dan Nicholson
none Details | Review

Description Andrej 2012-06-19 10:40:46 UTC
Created attachment 216730 [details] [review]
Proposed fix, but with a TODO (so not to be merged as-is, probably).

When a statically linked version of the library is used (under mingw32), the clock/thread init functions aren't called - this results in segfaults in various windows functions (and of course the app doesn't work).

This seems to be a result of the rework around the commit 47444dacc069be5984df4064ae382d45a9ae8c9e .

The reason seems to be that while DllMain() does call e.g. g_thread_win32_init(), the glib_init_ctor() doesn't.

Also, glib_init_ctor() doesn't seem to be used when a static version of the lib is compiled for win32.
Comment 1 Dan Nicholson 2012-08-17 18:56:52 UTC
Review of attachment 216730 [details] [review]:

I can confirm this is an issue with a static glib on win32 relative to glib-2.30.

::: glib-2.32.2.orig/glib/glib-init.c
@@ +225,3 @@
 HMODULE glib_dll;
 
+#if defined (G_OS_WIN32) && SHARED_BUILD

I think you need to keep the G_OS_WIN32 conditional around glib_dll otherwise it will be declared for all platforms, which is not what we want. Also, I think the proper thing to use here is GLIB_STATIC_COMPILATION since that's what's defined when --enable-static is passed to the build on win32. Here's what I came up with that's working:

@@ -225,6 +225,10 @@ glib_init (void)

 HMODULE glib_dll;

+#endif
+
+#if defined (G_OS_WIN32) && !defined (GLIB_STATIC_COMPILATION)
+
 BOOL WINAPI
 DllMain (HINSTANCE hinstDLL,
          DWORD     fdwReason,

@@ +266,3 @@
+   * static-linked app?
+   * glib_dll = GetModuleHandle(NULL);
+   */

I don't think it's necessary to set glib_dll here. It will be initialized to NULL above. It will then be passed to GetModuleHandleW in gutils.c:_glib_get_dll_directory. See the comment there about what happens with a static glib.

@@ +268,3 @@
+   */
+  g_clock_win32_init ();
+  g_thread_win32_init ();

I think these guys need to be wrapped in G_OS_WIN32 so they're not called on other platforms.
Comment 2 Dan Nicholson 2012-08-17 19:02:42 UTC
Created attachment 221665 [details] [review]
glib-init: Fully initialize from constructor when built static on win32

Here's an updated patch keeping Andrej as the author. This is working for me when I build static for linux or windows (I'm embedding glib in pkg-config).
Comment 3 Allison Karlitskaya (desrt) 2012-10-09 15:44:18 UTC
This is bug #660731.  As I mention there this is trickier than it seems because we depend on using DllMain() in the case of thread attach/detach.

I lean toward saying we should not support static compiles of glib...

*** This bug has been marked as a duplicate of bug 660731 ***