gparted crashes due to g_quark_from_static_string used in global initialization
Submitted by nco..@..ux.org
Link to original bug (#768215)
Description
gparted build with musl libc crashes with this error:
GLib:ERROR:gquark.c:60:g_quark_init: assertion failed: (quark_seq_id == 0)
backtrace:
Core was generated by `/usr/sbin/gpartedbin'. Program terminated with signal SIGABRT, Aborted.
#0 0x000074557d4fa45c in __syscall4 (a4=<optimized out>, a3=<optimized out>,
a2=<optimized out>, a1=<optimized out>, n=<optimized out>)
at ./arch/x86_64/syscall_arch.h:38
38 ./arch/x86_64/syscall_arch.h: No such file or directory.
(gdb) bt
#0 0x000074557d4fa45c in __syscall4 (a4=<optimized out>, a3=<optimized out>,
a2=<optimized out>, a1=<optimized out>, n=<optimized out>)
at ./arch/x86_64/syscall_arch.h:38
#1 __restore_sigs (set=set@entry=0x757e5fe06ab0) at src/signal/block.c:43
#2 0x000074557d4fa56d in raise (sig=sig@entry=6) at src/signal/raise.c:13
#3 0x000074557d4d2d01 in abort () at src/exit/abort.c:7
#4 0x000074557b60387f in g_assertion_message (
domain=domain@entry=0x74557b62b82e "GLib",
file=file@entry=0x74557b6272fa "gquark.c", line=line@entry=60,
func=func@entry=0x74557b627308 <__func__.4512> "g_quark_init",
message=<optimized out>,
message@entry=0x74557bad73c0 "assertion failed: (quark_seq_id == 0)")
at gtestutils.c:2429
#5 0x000074557b6038e4 in g_assertion_message_expr (
domain=domain@entry=0x74557b62b82e "GLib",
file=file@entry=0x74557b6272fa "gquark.c", line=line@entry=60,
func=func@entry=0x74557b627308 <__func__.4512> "g_quark_init",
expr=expr@entry=0x74557b6272e8 "quark_seq_id == 0") at gtestutils.c:2452
#6 0x000074557b5f38c1 in g_quark_init () at gquark.c:60
#7 0x000074557b5e6a2a in glib_init () at glib-init.c:243
#8 0x000074557d50c8fd in do_init_fini (p=0x12ffc8f2da0) at ldso/dynlink.c:1233
#9 0x000074557d4d2724 in __libc_start_main (
main=0x12ffc643bc4 <main(int, char**)>, argc=1, argv=0x757e5fe06e28)
at src/env/__libc_start_main.c:71
#10 0x0000012ffc644277 in _start_c (p=<optimized out>) at crt/crt1.c:17
#11 0x0000012ffc644252 in _start ()
So I added a watchpoint on quark_seq_id. on first break in gdb the backtrace shows:
(gdb) bt
#0 0x00007ffff5eb1883 in quark_new (string=<optimized out>) at gquark.c:299
#1 quark_from_string (string=<optimized out>, duplicate=0) at gquark.c:186
#2 0x00007ffff5eb198f in g_quark_from_static_string (
string=0x7ffff4e2fa3b "glibmm__Gio::Application::quark_extra_application_data") at gquark.c:246
#3 0x00007ffff4dc082d in ?? () from /usr/lib/libgiomm-2.4.so.1
#4 0x00007ffff7dca8fd in do_init_fini (p=0x7ffff55fade0)
at ldso/dynlink.c:1233
#5 0x00007ffff7d90724 in __libc_start_main (
main=0x5555555acbc4 <main(int, char**)>, argc=1, argv=0x7fffffffe108)
at src/env/__libc_start_main.c:71
#6 0x00005555555ad277 in _start_c (p=<optimized out>) at crt/crt1.c:17
#7 0x00005555555ad252 in _start ()
So what happens is that there is a global initialization using g_quark_from_static_string in glibmm/gio/src/application.ccg (https://git.gnome.org/browse/glibmm/tree/gio/src/application.ccg#n46)
This call to g_quark_from_static_string will increase the quark_seq_id (via quark_new) and it happens before the glib_init ctor has called g_quark_init, so when glib_init tries to initialize quark, it will trigger the assert.
This can be solved in various ways:
- revert commit 2fe992 (Move quark initialization to a constructor)
- call g_quark_init from quark_new (and have a static boolean to check that its only initialized once)
- call g_quark_init from g_quark_from_static_string (with static boolean check)
- say that its not allowed to use g_quark_from_static_string to initalize globals and tell glibmm to fix it other way.
Version: 2.48.x