FreeDink crashes on game load when compiled with -O2 or -Os

Bug #1322849 reported by Sylvain Beucler
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Raspbian
New
Undecided
Unassigned

Bug Description

Hi,

I'm the FreeDink maintainer and I've got a report of a segfault on game load:
http://www.dinknetwork.com/forum.cgi?MID=182045#182451

I recently got a Raspberry Pi myself and was able to confirm the issue.

The game segfaults following a NULL pointer derefence. The issues appears with -O2 or -Os, but there's no problem with -O0 or -O1.

Attempting to debug the issue failed to due a GDB issue (see below).
Manual code review didn't help me find a related bug (no path to get a NULL pointer, though theoretically there could be a memory mistwrite somewhere else).

FreeDink has been ported to numerous systems and architectures, such as GNU/Linux, Windows, FreeBSD, PSP, OpenPandora, etc. (https://www.gnu.org/software/freedink/get) and I never got such a report, so I'm wondering if there's something wrong with GCC.

I did get a close report on Fedora 19 though:
http://www.dinknetwork.com/forum.cgi?MID=182805
https://bugzilla.redhat.com/show_bug.cgi?id=1048020
BUT it disappeared after a mere RPM rebuild, and the segfault happened at a different place.
Which contributes to the GCC issue hypothesis.

What do you think?

- Segfault backtrace :

$ gdb --args /usr/games/freedink --window
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/games/freedink...Reading symbols from /usr/lib/debug/usr/games/freedink...done.
done.
(gdb) run
Starting program: /usr/games/freedink --window
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
[New Thread 0xb5f1a440 (LWP 20630)]
[New Thread 0xb54cf440 (LWP 20634)]

Program received signal SIGSEGV, Segmentation fault.
get_parms (proc_name=<optimized out>, script=1, str_params=0x45b54f "(\"&exp\",0);\n", spec=0x427cb0) at dinkc_bindings.c:2525
warning: Source file is more recent than executable.
2525 slist[i][0] = '\0';
(gdb) p i
$1 = <optimized out>
(gdb) p slist
$2 = {0x0, 0xbd3b98 "", 0x69e858 "", 0x69e868 "", 0x6a1c98 "", 0x6a1ca8 "", 0x6a1cb8 "", 0x42a7b8 "", 0x42a7c8 "", 0x42a7d8 ""}

- GDB watch internal issue :

$ gdb --args /usr/games/freedink --window
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/games/freedink...Reading symbols from /usr/lib/debug/usr/games/freedink...done.
done.
(gdb) watch slist[0]
Hardware watchpoint 1: slist[0]
(gdb) run
Starting program: /usr/games/freedink --window
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
[New Thread 0xb5f1a440 (LWP 20658)]
Hardware watchpoint 1: slist[0]

Old value = 0x0
New value = 0x6a1be0 ""
0x00013c90 in dinkc_bindings_init () at dinkc_bindings.c:2012
warning: Source file is more recent than executable.
2012 for (; i < 10; i++)
(gdb) c
Continuing.
/build/gdb-RHHfAt/gdb-7.4.1+dfsg/gdb/arm-linux-nat.c:1028: internal-error: arm_linux_remove_hw_breakpoint1: Assertion `i != count' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
/build/gdb-RHHfAt/gdb-7.4.1+dfsg/gdb/arm-linux-nat.c:1028: internal-error: arm_linux_remove_hw_breakpoint1: Assertion `i != count' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n
Stopped due to shared library event

Sylvain Beucler (beuc)
description: updated
Revision history for this message
peter green (plugwash) wrote :

Have you tried building with gcc 4.7?

Unfortunately raspbian seem to be one of very few projects that use armv6 hardfloat and we really dont' have the resources to chase this sort of bug beyond trying different compiler versions or settings and seeing if they go away.

Revision history for this message
Sylvain Beucler (beuc) wrote :

Thanks for the suggestion, I knew I would get some more ideas here :)

'CC=gcc-4.7' yields the same result, though :/

Both GDB and Valgrind won't work, do you have any debugging tool to recommend for this platform?

Revision history for this message
peter green (plugwash) wrote :

Not really, I've used gdb myself on raspbian but generally only very basic features (backtraces and disassembly mainly).

All I can suggest is doing things the old fassioned way using printf statements and/or cutting the code down manually.

Revision history for this message
Sylvain Beucler (beuc) wrote :

Note that I special-cased ARM in the packaging and now request -O1 (short of finding the real source of the problem).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.