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]

g++ Bug? use of alloca in a function prevents exception handler walkback on ppc linux


Hi,

Please cc any replies directly to me at: khendricks@ivey.uwo.ca

With a lot of help from Philipp Lohmann from Sun Germany, we have tracked the 
problem on ppc linux exception handling to the use of alloca in any function 
in the path back to the exception handler.

This is what causes the "pc" in throw_helper to point out into the weeds.

Is this a g++ bug?

Should dynamic allocation of stack space prevent the search back through the 
function by throw_helper?

Here is the test program and the results when run under gdb:

[kbhend@localhost kbhend]$ cat test_case.cxx
#include <malloc.h>
#include <stdio.h>
#include <string.h>

struct Exc
{
         int n;
};

void thrower()
{
         Exc aExc;
         throw aExc;
}

void caller( int n )
{
         void* pSpace = NULL;
         for( int i = 0; i < n; i++ )
         {
                 pSpace = alloca( n*(i+1) );
                 memset( pSpace, 0, n*(i+1) );
         }
         thrower();
}

int main( int argc, char** argv )
{
         try
         {
                 caller( 15 );
         }
         catch( Exc& )
         {
                 fprintf( stderr, "caught struct Exc&\n");
         }
         catch( ... )
         {
                 fprintf( stderr, "caught something\n");
         }
         return 0;
}


Note: I have compiled with -fPIC here since that is what is used for the 
openoffice bridge library but the same problem happens without -fPIC and when 
compiled at -O0 instead of -O2.  Also if you remove the alloca bits, the 
program actually catches the exception properly.

[kbhend@localhost kbhend]$ g++ -O2 -fexceptions -fPIC -o test_case 
test_case.cxx[kbhend@localhost kbhend]$ ./test_case
Aborted (core dumped)

[kbhend@localhost kbhend]$ gdb ./test_case
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc-unknown-linux-gnu"...
(gdb) b main     
Breakpoint 1 at 0x100008c4
(gdb) run
Starting program: /home/kbhend/./test_case 

Breakpoint 1, 0x100008c4 in main ()
(gdb) c
Continuing.

Program received signal SIGABRT, Aborted.
0xfe4eea0 in kill () at soinit.c:59
59	soinit.c: No such file or directory.
(gdb) bt
#0  0xfe4eea0 in kill () at soinit.c:59
#1  0xfe4eb68 in raise (sig=6) at ../sysdeps/posix/raise.c:27
#2  0xfe50400 in abort () at ../sysdeps/generic/abort.c:88
#3  0xffbbd08 in __default_terminate () from /usr/lib/libstdc++-libc6.1-2.so.3
#4  0xffbbd40 in __terminate () from /usr/lib/libstdc++-libc6.1-2.so.3
#5  0xffbcb70 in throw_helper (eh=0xffefc9c, pc=0xffffffff, 
    my_udata=0x7fffef38, offset_p=0x7ffff0d8)
   from /usr/lib/libstdc++-libc6.1-2.so.3
#6  0xffbcdc8 in __throw () from /usr/lib/libstdc++-libc6.1-2.so.3
#7  0x10000820 in caller ()
#8  0x10000884 in caller ()
#9  0x100008d4 in main ()
#10 0xfe4773c in __libc_start_main (argc=1, argv=0x7ffffa94, envp=0x7ffffa9c, 
    auxvec=0x7ffffb0c, rtld_fini=0, stinfo=0x10000af4, 
    stack_on_entry=0x7fffe860) at ../sysdeps/powerpc/elf/libc-start.c:106
(gdb)


Any guidance about how to deal with this would be greatly appreciated.

Thanks,

Kevin
---
Kevin B. Hendricks, Associate Professor
Operations and Information Technology
Richard Ivey School of Business, UWO, London ON, CANADA
(519) 661-3874

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