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 686822 - possible dlopen()/dlclose() issue with automatic g_type_init()
possible dlopen()/dlclose() issue with automatic g_type_init()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 686698 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-10-24 20:15 UTC by Colin Walters
Modified: 2012-10-27 16:30 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
backtrace (2.92 KB, text/plain)
2012-10-24 20:16 UTC, Colin Walters
  Details
More bactracing requested by walters (2.92 KB, text/plain)
2012-10-24 20:35 UTC, Darxus
  Details
backtraces of gobject_init_ctor (3.26 KB, text/plain)
2012-10-24 20:39 UTC, Darxus
  Details
queryloaders: Ensure we link to libgobject (1.80 KB, patch)
2012-10-24 21:21 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2012-10-24 20:15:46 UTC
We have a segfault reported from gdk-pixbuf-query-loaders that includes the new gobject_init_ctor().

An initial theory here is that if dlclose() has been called, we'll crash when re-entering.  See the attached stack.
Comment 1 Colin Walters 2012-10-24 20:16:09 UTC
Created attachment 227192 [details]
backtrace
Comment 2 Darxus 2012-10-24 20:35:12 UTC
Created attachment 227195 [details]
More bactracing requested by walters

Output of:

libtool --mode=execute gdb --args ../gdk-pixbuf/gdk-pixbuf-query-loaders libpixbufloader-pcx.la libpixbufloader-png.la
b gobject_init_ctor
r
t a a bt
c
t a a bt
q
Comment 3 Darxus 2012-10-24 20:39:18 UTC
Created attachment 227196 [details]
backtraces of gobject_init_ctor

That last file was wrong, this should be right.
Comment 4 Colin Walters 2012-10-24 21:21:12 UTC
Created attachment 227203 [details] [review]
queryloaders: Ensure we link to libgobject

This call is necessary to ensure we actually link against libgobject;
otherwise it may be stripped if -Wl,--as-needed is in use.

The reason we need to link against libgobject is because it now has
a global constructor.  If the dynamically loaded modules happen
to dlclose() libgobject, then reopen it again, we're in for trouble.

See https://bugzilla.gnome.org/show_bug.cgi?id=686822

Patch-suggested-by: Ryan Lortie <desrt@desrt.ca>
Signed-off-by: Colin Walters <walters@verbum.org>
Comment 5 Darxus 2012-10-24 22:12:18 UTC
This patch puts "g_type_ensure (G_TYPE_OBJECT);" within a #ifdef G_OS_WIN32, so it doesn't get called for me.  Moving it to immediately after the following #endif does make ldd now say that it's linking to libgobject-2.0.so.0 (which it wasn't before).  Which I believe does fix my problem.

Shortly after, I'm getting:

/usr/bin/ld: /home/darxus/source.test.master/gdk-pixbuf/gdk-pixbuf/tmp-introspectGGuCWy/GdkPixbuf-2.0.o: undefined reference to symbol 'g_module_open'

Which I think is not directly related?
Comment 6 Colin Walters 2012-10-24 22:21:34 UTC
Comment on attachment 227203 [details] [review]
queryloaders: Ensure we link to libgobject

Attachment 227203 [details] pushed as 3a0531d - queryloaders: Ensure we link to libgobject
Comment 7 Colin Walters 2012-10-24 22:22:32 UTC
(In reply to comment #5)
> This patch puts "g_type_ensure (G_TYPE_OBJECT);" within a #ifdef G_OS_WIN32, so
> it doesn't get called for me.  

Argh, my bad.  Sorry about that...I had such high confidence in the patch I didn't
even bother to check it was being called in gdb.

> Moving it to immediately after the following
> #endif does make ldd now say that it's linking to libgobject-2.0.so.0 (which it
> wasn't before).  Which I believe does fix my problem.

Pushed then, thanks.
Comment 8 Simon Feltman 2012-10-25 03:01:59 UTC
*** Bug 686698 has been marked as a duplicate of this bug. ***
Comment 9 Matthias Clasen 2012-10-26 23:40:34 UTC
Colin, can you put a warning about this possible pitfall of removing the explicit g_type_init call to README.in ?
Comment 10 Colin Walters 2012-10-27 16:30:19 UTC
(In reply to comment #9)
> Colin, can you put a warning about this possible pitfall of removing the
> explicit g_type_init call to README.in ?

Done.