[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#317233: gcc-4.0 regression, possibly powerpc-specific, causes segfault in compiled binary



Matthias Klose <doko@cs.tu-berlin.de> writes:

retitle 317233 gcc-4.0 regression causes segfault in compiled binary
thanks

> yes, it would be useful. is this powerpc specific, or is seen on other
> archs as well?

It's also been confirmed on i386 (all the previous info applies
equally to i386 as well as powerpc).  The cause is not apparent
however.

Because the test case works, _and_ adding const works, exactly what
changed is not at all clear.  The fault is in IA__g_str_hash(), called
from g_option_context_parse() in parse_options().  gdb shows that the
argc and argv passed to g_option_context_parse are not corrupted on
entry.  Matthijs Mohlmann reports random corruption of argc though
(but it varies from run to run).

>From #debian-bugs:

Active2: do you want a backtrace ?
rleigh:  Yes please (gdb is broken on ppc for me).  Could you next
         change 'static GOptionEntry entries[] =' to 'static const
         GOptionEntry entries[] =' in schroot/schroot.c, and try
         again?

Active2: can i paste here ?
rleigh:  Sure.
Active2: #0  0xb7f631e7 in g_str_hash () from /usr/lib/libglib-2.0.so.0
Active2: #1  0xb7f3d7a4 in g_hash_table_insert () from /usr/lib/libglib-2.0.so.0
Active2: #2  0xb7f5606d in g_option_context_add_main_entries ()
Active2:     from /usr/lib/libglib-2.0.so.0
Active2: #3  0xb7f57af7 in g_option_context_parse () from /usr/lib/libglib-2.0.so.0

rleigh:  Thanks.  Could you try adding the const keyword, and try
         again?
Active2: now it is solved with the const keyword
rleigh:  Bizarre!  I can't see any reason why making it const should do
         that, since g_option_context_add_main_entries() takes a const
         pointer.  It shouldn't matter that the object isn't actually
         const.

rleigh:  Please could you try building the patch here:
         http://bugs.debian.org/cgi-bin/bugreport.cgi/schroot.c?bug=317233&msg=12&att=1
rleigh:  Build with gcc -o schroot schroot.c `pkg-config --cflags --libs gobject-2.0`
rleigh:  This doesn't add the const, but strips out other bits.
Active2: works
rleigh:  Thanks.  So it's identical to powerpc.
Active2: np

rleigh:  Now for the hard question!  Any idea what's going on?
Active2: is glib already compiled with the new gcc ? i don't know if
         that can be a problem
rleigh:  Active2: not yet; it shouldn't be needed for C code.
rleigh:  I'll rebuild it to see.

Active2: sometimes it goes ok and sometimes it segfaults
Active2: #4  0x0804a4da in main (argc=1601463655, argv=0x5f746567) at schroot.c:93
Active2:         config = Variable "config" is not available.
rleigh:  Is this with the const or without?
Active2: without
rleigh:  The original, or the testcase from the bug report?
Active2: The original

Active2: rleigh, is this ok:
Active2: (gdb) print argc
Active2: $2 = -1073742940
Active2: that's in parse_options
rleigh:  Active2: No; that's very broken.  I've seen that happen
         before, I just can't remember why.  Memory corruption is
         likely.

rleigh:  Active2: Could you try 'nm schroot/schroot | grep
         parse_options'?  For some reason the symbol is not visible.
Active2: matthijs@monster % nm /usr/bin/schroot| grep parse_options                    ~
Active2: matthijs@monster %

Active2: rleigh, can you try the following:
Active2: replace 'parse_options(argc, argv);' with
         'parse_options(&argc, argv);' in the main function
rleigh:  Active2: It segfaults in IA__g_str_hash().
rleigh:  (and also if I change parse_options to take an int *argc)
Active2: no segfault here, but what i don't understand is:

Active2: when i run schroot --help (with gdb) i get this:
Active2: Breakpoint 1, main (argc=2, argv=0x1) at schroot.c:201
Active2: is the argc right ?
Active2: I don't know how to fix that
rleigh:  Yes.  argv[] will be set to {"schroot", "--help", NULL};
         i.e. 2 options (argv[0] is typically the program name, and
         the options follow that).
Active2: rleigh, testing with a simple c program it works (argc gets
         the correct value in the function i pass argc to) so it must
         go fault earlier
Active2: sorry i'm out of options
rleigh:  Active2: I'm not sure.  breaking on g_option_context_parse
         shows argc == 2.



Regards.
Roger

-- 
Roger Leigh
                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                Debian GNU/Linux        http://www.debian.org/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.



Reply to: