If I compile GLib normally on a 64-bit platform, without CFLAGS=-g, run a test program, and `print sizeof(__glib_assert_msg)`, gdb (incorrectly) tells me it’s 4 bytes: However, it’s a char*, and its size according to objdump is (correctly) 8 bytes: (gdb) print sizeof(__glib_assert_msg) $1 = 4 (gdb) print sizeof(char*) $2 = 8 objdump -t ./glib/.libs/libglib-2.0.so.0.5400.2 | grep assert_msg 000000000032c3e0 g O .bss 0000000000000008 __glib_assert_msg No debug information is being loaded while running gdb: (gdb) info sharedlibrary From To Syms Read Shared Object Library 0x00007ffff7dd9aa0 0x00007ffff7df51b0 Yes /lib64/ld-linux-x86-64.so.2 0x00007ffff7ac6e90 0x00007ffff7b5ae90 Yes (*) /tmp/build-snapshot.Ry9JWQsWNS/s/glib/.libs/libglib-2.0.so.0 0x00007ffff772c910 0x00007ffff7856423 Yes /lib/x86_64-linux-gnu/libc.so.6 0x00007ffff749b5d0 0x00007ffff74edab1 Yes (*) /lib/x86_64-linux-gnu/libpcre.so.3 0x00007ffff7282ab0 0x00007ffff728f811 Yes /lib/x86_64-linux-gnu/libpthread.so.0 (*): Shared library is missing debugging information. I can provide other information if needed. --- This looks similar to bug #12281. The downstream GLib bug which triggered this is https://bugzilla.gnome.org/show_bug.cgi?id=782057.
The problem is that without debug info (-g), GDB can't know that "__glib_assert_msg" is a "char *". And then, in all released versions, if GDB doesn't know the type of the object, it assumes "int", which has sizeof 4. This assumption was recently removed in GDB master (soon-to-be gdb 8.1), exactly because it's very confusing: https://sourceware.org/ml/gdb-patches/2017-07/msg00137.html specifically: https://sourceware.org/ml/gdb-patches/2017-07/msg00150.html
(In reply to Pedro Alves from comment #1) > The problem is that without debug info (-g), GDB can't know that > "__glib_assert_msg" is a "char *". And then, in all released versions, > if GDB doesn't know the type of the object, it assumes "int", > which has sizeof 4. > > This assumption was recently removed in GDB master (soon-to-be gdb 8.1), > exactly because it's very confusing: > https://sourceware.org/ml/gdb-patches/2017-07/msg00137.html > specifically: > https://sourceware.org/ml/gdb-patches/2017-07/msg00150.html I see, that explains things. I look forward to your patch series landing. Is there a bug which this one should be duped to?
(In reply to Philip Withnall from comment #2) > I see, that explains things. I look forward to your patch series landing. It already landed a while ago. If you try out current master, you'll get an error instead of "= 4". > Is there a bug which this one should be duped to? There probably is, though I haven't looked. This is a very frequent source of confusion. For sizeof in particular, I'm wondering whether it makes sense (or rather if it could ever be a problem) for GDB to use/print the size as recorded in the ELF symbol table, when it is available. That might be doable. (though I probably won't be able to try it myself soon enough). Not sure it's worth the trouble, though.
Was fixed some time ago.