lua-users home
lua-l archive

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

On Sat, 2005-02-05 at 00:50, Adam D. Moss wrote:
> Hi there!
> I thought I'd warn fellow Lua users about something which has
> caused me quite a lot of debugging anguish: it's not safe to compile
> Lua with -fomit-frame-pointer if you're compiling with mingw. 

Which gcc version?

I ask because I'm using g++, and if you
specify -O3 and -fomit-frame-pointer with g++ 3.2.2 it
screws up when you throw an exception.

I asked on the g++ help newsgroup, but didn't get
any answers. The author of the code concerned suggested
it could be a bug in his C++ code hidden by luck
by some compilation options (but I don't believe it).

Your report suggests its a bug in the gcc backend
related to stack management, which is related to
both throwing exceptions and setjump/longjump,
or a bug in some library code.

However my code works with -O2, or without 
-fomit-frame-pointer. Bottom line -- this might not
be a Mingw specific problem.

BTW: I'm not surprised. gcc is written in C, which is
not a very good language for writing high level apps,
especially compilers. Code using SP instead of BP
to find local variables is very much trickier
to implement (since evert stack push changes the
offsets). So I wouldn't be surprised if there
were some kind of bug. It could be in the library
though.. very hard to pin down.

In C++ I tracked this down to 'unexpected()' aborting
the program, which is correct behaviour for an uncaught
exception .. only there was a proper catch for the exception
which actually catches it with other compiler flags,
so the bug isn't in the source.

I'm now going to bet, from your bug report, that the library
code to restore an old stack (also used catching an exception)
incorrectly sets the BP register. Probably the library
code (which has to be written in assembler) is assuming
some relation between SP/BP which only holds when
the frame pointer is actually managed.

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language