Gcc generating illegal instructions

Hi all,

I’ve been trying to write a relatively simple patch for SDL, but my
gcc is generating code that gets SIGILLed!

donny at teamspace:~/SDL/test$ gcc --version
gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Copyright © 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This build is from the Debian Etch/stable repository. What is the
policy on avoiding bugs in a particular compiler? What if I can’t
figure out how to avoid the bug? I’ve installed gcc 3.3 and I plan on
trying that to see if it works any better. Is there a list of
compilers we must agree with or bust?–
http://codebad.com/

Hi Donny-

As far as I understand, gcc 4.1.x is a set of beta releases. As such,
I’d suggest trying either gcc 4.2 or gcc 4.0 before jumping right back
to the gcc 3.x series.
What architecture, by the way?

AlastairOn 2 Jan 2009, at 22:58, Donny Viszneki wrote:

Hi all,

I’ve been trying to write a relatively simple patch for SDL, but my
gcc is generating code that gets SIGILLed!

donny at teamspace:~/SDL/test$ gcc --version
gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Copyright © 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

This build is from the Debian Etch/stable repository. What is the
policy on avoiding bugs in a particular compiler? What if I can’t
figure out how to avoid the bug? I’ve installed gcc 3.3 and I plan on
trying that to see if it works any better. Is there a list of
compilers we must agree with or bust?


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3912 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090102/375d8a1a/attachment.bin

As far as I understand, gcc 4.1.x is a set of beta releases. As such, I’d
suggest trying either gcc 4.2 or gcc 4.0 before jumping right back to the
gcc 3.x series.

Ah, thanks for the info Alastair, I just assumed if it was in Debian
stable, it was considered pretty safe. Guess I should be more careful
about that sort of thing…

What architecture, by the way?

i686On Fri, Jan 2, 2009 at 6:00 PM, Alastair Lynn wrote:


http://codebad.com/

Argh… I installed gcc 3.3, cleaned SDL, reconfigured with gcc 3.3,
recompiled, reinstalled, rebuilt my test, and still had the same
problem :frowning: :frowning: :(On Fri, Jan 2, 2009 at 6:03 PM, Donny Viszneki <@Donny_Viszneki> wrote:

On Fri, Jan 2, 2009 at 6:00 PM, Alastair Lynn wrote:

As far as I understand, gcc 4.1.x is a set of beta releases. As such, I’d
suggest trying either gcc 4.2 or gcc 4.0 before jumping right back to the
gcc 3.x series.

Ah, thanks for the info Alastair, I just assumed if it was in Debian
stable, it was considered pretty safe. Guess I should be more careful
about that sort of thing…


http://codebad.com/

Hi all,

I’ve been trying to write a relatively simple patch for SDL, but my
gcc is generating code that gets SIGILLed!

donny at teamspace:~/SDL/test$ gcc --version
gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Copyright © 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This build is from the Debian Etch/stable repository. What is the
policy on avoiding bugs in a particular compiler? What if I can’t
figure out how to avoid the bug? I’ve installed gcc 3.3 and I plan on
trying that to see if it works any better. Is there a list of
compilers we must agree with or bust?

What is the backtrace? What are the compiler options being used to build SDL?

See ya,
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

As far as I understand, gcc 4.1.x is a set of beta releases. As
such, I’d
suggest trying either gcc 4.2 or gcc 4.0 before jumping right back
to the
gcc 3.x series.

Ah, thanks for the info Alastair, I just assumed if it was in Debian
stable, it was considered pretty safe. Guess I should be more careful
about that sort of thing…

Argh… I installed gcc 3.3, cleaned SDL, reconfigured with gcc 3.3,
recompiled, reinstalled, rebuilt my test, and still had the same
problem :frowning: :frowning: :frowning:

Such errors could also indicate some hardware problems or too less
memory. I often had similar errors when I tried to compile a very big
package (like KDE or Qt) with only 256MB of memory.

If you are sure that is not the case for you, perhaps post the problem
in the GCC bugtracker.Am 03.01.2009 um 00:10 schrieb Donny Viszneki:

On Fri, Jan 2, 2009 at 6:03 PM, Donny Viszneki <donny.viszneki at gmail.com wrote:

On Fri, Jan 2, 2009 at 6:00 PM, Alastair Lynn wrote:

What is the backtrace? What are the compiler options being used to build SDL?

Such errors could also indicate some hardware problems or too less memory. I
often had similar errors when I tried to compile a very big package (like
KDE or Qt) with only 256MB of memory.

Yeah I hope there’s nothing wrong with my machine. I’ve never heard of
that second thing though. Both possibilities are a little scary.

If you are sure that is not the case for you, perhaps post the problem in
the GCC bugtracker.

I’m certainly considering it. In the meantime I’ve found that if I use
doubles instead of floats, the problem doesn’t seem to show up. In any
case I’ll be sure to try to put together a test case at some point in
the future – but I doubt that will be today.

Maybe I’ll run a memory test overnight…On Fri, Jan 2, 2009 at 6:50 PM, Sam Lantinga wrote:
On Fri, Jan 2, 2009 at 6:50 PM, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:


http://codebad.com/

“Donny Viszneki” <donny.viszneki at gmail.com> schrieb am 03.01.2009 01:10:39:

What is the backtrace? What are the compiler options being used to build SDL?

Good point … I had recently problems with the -O2 optimization with access to PCI interfaces.

An other point could be the configuration of the data segment … if a string is overwriting the assigned space of a character array it is possible that this makes no visible problems with an older gcc. But with gcc 4.x the application will crash … happened to me recently. As you know: absent of failures doesn’t mean your code is error free …

Regards

–Armin> On Fri, Jan 2, 2009 at 6:50 PM, Sam Lantinga wrote:

On Fri, Jan 2, 2009 at 6:50 PM, Albert Zeyer <albert.zeyer at rwth-aachen.de> wrote:

Such errors could also indicate some hardware problems or too less memory. I
often had similar errors when I tried to compile a very big package (like
KDE or Qt) with only 256MB of memory.

Yeah I hope there’s nothing wrong with my machine. I’ve never heard of
that second thing though. Both possibilities are a little scary.

If you are sure that is not the case for you, perhaps post the problem in
the GCC bugtracker.

I’m certainly considering it. In the meantime I’ve found that if I use
doubles instead of floats, the problem doesn’t seem to show up. In any
case I’ll be sure to try to put together a test case at some point in
the future – but I doubt that will be today.

Maybe I’ll run a memory test overnight…


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Psssst! Schon vom neuen WEB.DE MultiMessenger geh?rt?
Der kann`s mit allen: http://www.produkte.web.de/messenger/?did=3123

This can also be a trivial bug in your code (say, a buffer overflow):

For example, you have a N-byte local buffer in your procedure (N is
not very small).
Then your stack frame looks like this:

… other locals etc …
EBP - 4*N:
DWORD buffer[N]
EBP:
(old ebp)
EBP + 4:
Return address
EBP + 8:
… function arguments …

So, when you write to buffer[N+1], you overwrite your return address,
and at the next RET you’ll try to jump to some random point in memory,
and it is possible that it is allocated and is OK to execute (so you
don’t get a SIGSEGV), but contains some data that looks like illegal
instructions.

Regards,
Alex

True. In my case though, tracing through program execution shows that
the code being executed is in a segment where that can’t happen. Good
advice!On Sat, Jan 3, 2009 at 9:19 AM, Alexander Shpilkin wrote:

This can also be a trivial bug in your code (say, a buffer overflow):

For example, you have a N-byte local buffer in your procedure (N is
not very small).
Then your stack frame looks like this:

… other locals etc …
EBP - 4*N:
DWORD buffer[N]
EBP:
(old ebp)
EBP + 4:
Return address
EBP + 8:
… function arguments …

So, when you write to buffer[N+1], you overwrite your return address,
and at the next RET you’ll try to jump to some random point in memory,
and it is possible that it is allocated and is OK to execute (so you
don’t get a SIGSEGV), but contains some data that looks like illegal
instructions.

Regards,
Alex


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/

2009/1/2 Alastair Lynn :

Hi Donny-

As far as I understand, gcc 4.1.x is a set of beta releases. As such, I’d
suggest trying either gcc 4.2 or gcc 4.0 before jumping right back to the
gcc 3.x series.

Hi,

Your understanding is incorrect. GCC does not use Linux kernel-style
experimental/stable numbering. The switch from 3.x to 4.x incorporated
some fundamental changes so jumping back to the 3.x series isn’t as
daft as it sounds…

GCC is a 2-stage compiler (like most C/C++ compilers); it actually
outputs assembly code which is then passed to an assembler, so an
’illegal instruction’ is probably due to dodgy binutils, rather than
GCC proper… or an error in your code (esp. true if you’ve tried a
different compiler).

Eddy