This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

DWARF-2 Exception Handling in C++: Please Help!


Hi,

    I request the help of DW2 EH gurus here in trying
to solve a particularly pesky problem related to
exception propagation in C++ with the cygwin/mingw32
targets.

With GCC 3.x the Cygwin/MinGW projects had moved to
DW2-based Exception Handling. However, there are some
cases in which DW2 EH is not working and these projects
have all but decided to switch back to SJLJ. Having
understood what I have of EH in C++ and the way SJLJ and
DW2 based EH works, I'm completely convinced that DW2
EH is the way to go - if only we could iron out these
bugs. Hence this desperate plea!

Here's a simple C++ program that fails with DW2 EH
on MinGW/GCC 3.2:
-------------------------- 8< --------------------------
void __attribute__((stdcall)) test( int a) { a; }

void snafu( void) {
    test( 666);
    throw 999;
}

int main( void) {
    try {
        snafu( );
        return 0;
    } catch( ...) {
        return 1;
    }
}
-------------------------- 8< --------------------------

(The "stdcall" calling convention places the burden
of cleaning up the stack on the *called* function (like
in Pascal). The "fastcall" calling convention is similar
to "stdcall", except that the first two arguments are
passed in the ECX and EDX registers of the x86 CPUs.)

When this program is compiled with g++ normally, everthing
is hunky dory - however, if compiled with "-fomit-frame-pointer",
it aborts. (I'm using GCC 3.2 and binutils 2.13 with MinGW
local patches.)

Here are a few of my observations on the problem cited
above:

1. The problem happens *only if at least one argument* is passed
   to the test( ) function.

2. The problem also happens if the test( ) function is marked
   "fastcall", but this time, as expected, at least three
   arguments are needed to show the problem.

3. The problem *does not happen* on Linux with GCC 3.2. (Linux
   GCC 3.2 does honour stdcall/fastcall and uses DW2 EH.)

4. The problem does not happen if -momit-leaf-frame-pointer is
   used instead of -fomit-frame-pointer.

5. If I remove the stdcall attribute of the test function and
   use "-mrtd -fomit-frame-pointer" instead, the problem still
   occurs and does not happen if vanilla "-mrtd" is used.

6. MinGW/Cygwin uses a set of "shared pointers" for seen_objects,
   unseen_objects, etc. needed to propagate exceptions across
   DLL/EXE boundaries - I removed this patch from GCC and the
   problem still occurs.

7. The MinGW/Cygwin GCC is able to access unaligned data - it
   at least passes the "packed-1.c" and "packed-2.c" testcases
   in the GCC testsuite (in gcc.c-torture/execute).

8. I changed the ".align" gas directives from the generated
   assembler output to explicitly use 0x00 for padding, but the
   problem still persists. (It was reported in an earlier
   message that the x86 "NOP" instruction used as a pad for
   code sections by the assembler, can confuse the DW2
   unwinding code.)

9. Trying to debug the executable with GDB 5.2.1 and debug
   versions of libstdc++-v3 and libsupc++ showed me that
   _Unwind_RaiseException actually returns with a URC_END_OF_STACK
   error, causing __cxa_throw to call std::terminate( ).

I'm attaching the assembler output ("-S -dA") for the
program with and without the "-fomit-frame-pointer" flag,
as a TGZ compressed archive (1K) with this mail. I could
not figure out the problem using these.

BTW I have read (and re-read) the following documents -
they have helped me a lot in understanding what's going
on:

http://www.usenix.org/events/osdi2000/wiess2000/full_papers/dinechin/dinechin_html/
http://gcc.gnu.org/ml/gcc/2002-07/msg00391.html
http://www.codesourcery.com/cxx-abi/abi-eh.html

This problem has been driving me completely nuts and
I seem to have exhausted all options with my limited
capabilities - any help or insight in this matter
would be greatly appreciated!

Thanks a lot for your patience.

Sincerely Yours,
Ranjit.

--
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/

Attachment: fooasm.tgz
Description: application/compressed


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]