Uncatchable exceptions on some systems.

2007-07-09 Thread Joshua ChaitinPollak
Hello,

I'm at my wits end. I'm building a C++ application for an embedded
device, but I'm having trouble catching exceptions within the embedded
environment. The exact same code works fine on my regular desktop
environment, with the same version of GCC (4.1.2).

I've been able to boil this down to a single source file and one compile
command:

g++ -fexceptions -frtti -o program program.cpp

Here is my program, the output from each environment, along with the
output from 'g++ -v' is below.

Thanks for any help you can give, I'm not even sure how to begin
diagnosing this further, so any hints would be appreciated.

-Josh

// BEGIN EXCEPTION TEST
#include 

class test {
  public:
  test() throw(std::exception);
};

test::test() throw(std::exception) {
throw std::exception();
}

int main() {
  try {
test t;
  }
  catch(std::exception e) {
std::cout << "caught" << std::endl;
  }

  return 0;
}
// END EXCEPTION TEST


Here is what happens when I run from my embedded environment:

moya exceptionTest # g++ -fexceptions -frtti -o program program.cpp
moya exceptionTest # ./program 
terminate called after throwing an instance of 'std::exception'
terminate called recursively
Aborted (core dumped)
moya exceptionTest # g++ -v
Using built-in specs.
Target: i586-gentoo-linux-uclibc
Configured
with: /var/tmp/portage/sys-devel/gcc-4.1.2/work/gcc-4.1.2/configure
--prefix=/usr --bindir=/usr/i586-gentoo-linux-uclibc/gcc-bin/4.1.2
--includedir=/usr/lib/gcc/i586-gentoo-linux-uclibc/4.1.2/include
--datadir=/usr/share/gcc-data/i586-gentoo-linux-uclibc/4.1.2
--mandir=/usr/share/gcc-data/i586-gentoo-linux-uclibc/4.1.2/man
--infodir=/usr/share/gcc-data/i586-gentoo-linux-uclibc/4.1.2/info
--with-gxx-include-dir=/usr/lib/gcc/i586-gentoo-linux-uclibc/4.1.2/include/g++-v4
 --host=i586-gentoo-linux-uclibc --build=i586-gentoo-linux-uclibc 
--disable-altivec --disable-nls --with-system-zlib --disable-checking 
--disable-werror --enable-secureplt --disable-multilib --disable-libmudflap 
--disable-libssp --disable-libgcj --enable-languages=c,c++ --enable-shared 
--enable-threads=posix --disable-__cxa_atexit --enable-target-optspace 
--enable-clocale=uclibc
Thread model: posix
gcc version 4.1.2 (Gentoo 4.1.2)

Here is what happens when I run from my desktop environment:

[EMAIL PROTECTED]:~/src/exceptionTest$ g++ -fexceptions -frtti -o program
program.cpp 
[EMAIL PROTECTED]:~/src/exceptionTest$ ./program 
caught
[EMAIL PROTECTED]:~/src/exceptionTest$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c
++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --program-suffix=-4.1
--enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug
--enable-mpfr --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 (Ubuntu 4.1.2-0ubuntu4)




Re: Uncatchable exceptions on some systems.

2007-07-09 Thread Joshua ChaitinPollak


On Jul 9, 2007, at 1:43 PM, David Daney wrote:


You don't say what version of uclibc you are using.
The last time I checked, exception handling on uClibc was foobar.   
I am not sure if it is true for the versions you are using.  There  
may be patches floating around that make things work (I know I  
posted some a while back.)


David Daney.



I'm using 0.9.28. I didn't realize uclibc could affect this. Can you  
recommend a version where exceptions work?


--
Joshua ChaitinPollak
Software Engineer
Kiva Systems




Re: Uncatchable exceptions on some systems.

2007-07-09 Thread Joshua ChaitinPollak

On Jul 9, 2007, at 2:22 PM, David Daney wrote:


Joshua ChaitinPollak wrote:

On Jul 9, 2007, at 1:43 PM, David Daney wrote:


You don't say what version of uclibc you are using.
The last time I checked, exception handling on uClibc was  
foobar.  I am not sure if it is true for the versions you are  
using.  There may be patches floating around that make things  
work (I know I posted some a while back.)


David Daney.

I'm using 0.9.28. I didn't realize uclibc could affect this. Can  
you recommend a version where exceptions work?

The problems are in GCC not uClibc.

See: http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00815.html

That was just a prototype patch and it has been a while since I  
tried it so I don't know if it is still sufficient.


Basically you need to disable -Dinhibit_libc and have the proper  
dwarf2 exception handling code built into libgcc.


In some cases there are problems getting the proper libraries  
linked so that dl_iterate_pheader (sp?) is resolved in uClibc.


David Daney


I was able to resolve this problem by recompiling gcc with "--enable- 
sjlj-exceptions --enable-__cxa_atexit" I'm not sure which (or both)  
are needed, but they solved my problem.


Thanks to David for pointing me in the right direction,

-Josh

--
Joshua ChaitinPollak
Software Engineer
Kiva Systems