title: Android NDK toolchain exception handling seg faults
body: <p>I've written a simple c++ test program to test exceptions</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  inline bool isNumber(char c);
  
  inline unsigned stringToNum(const char *str) {
      unsigned x = 0;
      const char *p = str;
      while(1) {
          if( !isNumber(*p) ) {  
              if( *p == 0 &amp;&amp; p != str )
                  break;
              throw 0;
          }
          x = x * 10 + *p++ - '0';
      }
      return x;
  }
  
  inline bool isNumber( char c ) {
      return c &gt;= '0' &amp;&amp; c &lt;= '9';
  }
  
  int main() {
      std::string k = std::string("test");
      try {
          int p = stringToNum(k.c_str());
      } catch(...) {
          std::cout &lt;&lt; "EXCEPTION THROWN";
      }
  }
  </code></pre>
  
  <p>I'm compiling the program in two stages (I'm attempting to simulate an error occuring with a much larger library). The first step looks like</p>
  
  <pre><code>/Users/me/android-ndk-r8/toolchains/x86-4.4.3/prebuilt/darwin-x86/bin/i686-android-linux-g++ -c -fexceptions -frtti -Wnon-virtual-dtor -Woverloaded-virtual --sysroot "/Users/me/android-ndk-r8/platforms/android-14/arch-x86/"  -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -O3 -Wl,-rpath-link=/Users/me/android-ndk-r8/platforms/android-14/arch-x86/usr/lib/ -L/Users/me/android-ndk-r8/platforms/android-14/arch-x86/usr/lib/ -nostdlib /Users/me/android-ndk-r8/platforms/android-14/arch-x86/usr/lib/crtbegin_dynamic.o -lc -lm -I/Users/me/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/include -I/Users/me/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/libs/x86/include exceptiontest.cpp
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>/Users/me/android-ndk-r8/toolchains/x86-4.4.3/prebuilt/darwin-x86/bin/i686-android-linux-g++ -fexceptions -fPIC -pthread -rdynamic --sysroot "/Users/me/android-ndk-r8/platforms/android-14/arch-x86/" -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -O3 -Wl,-rpath-link=/Users/me/android-ndk-r8/platforms/android-14/arch-x86/usr/lib/ -L/Users/me/android-ndk-r8/platforms/android-14/arch-x86/usr/lib/ -nostdlib /Users/me/android-ndk-r8/platforms/android-14/arch-x86/usr/lib/crtbegin_dynamic.o -lc -lm exceptiontest.o -L/Users/me/android-ndk-r8/toolchains/x86-4.4.3/prebuilt/darwin-x86/lib/gcc/i686-android-linux/4.4.3 -L/Users/me/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/libs/x86 -lgnustl_shared -lgcc
  </code></pre>
  
  <p>When I run a.out on the device (with libgnustl_shared.so copied over to the libs directory), I get a segfault. What am I missing? compiler flag? library? etc.</p>
  
  <p>edit: heres a stacktrace of the segfault off gdb</p>
  
  <pre><code>#0  get_cie_encoding (cie=0x6107daff) at /Users/andrewhsieh/ndk-andrewhsieh/src.1-with-cherrypicks//build/../gcc/gcc-4.4.3/libgcc/../gcc/unwind-dw2-fde.c:267
  #1  0x080b16d8 in classify_object_over_fdes (ob=0x80d8b68, this_fde=0x80d0a1c) at /Users/andrewhsieh/ndk-andrewhsieh/src.1-with-cherrypicks//build/../gcc/gcc-4.4.3/libgcc/../gcc/unwind-dw2-fde.c:615
  #2  0x080b1a5d in search_object (ob=0x80d8b68, pc=&lt;value optimized out&gt;) at /Users/andrewhsieh/ndk-andrewhsieh/src.1-with-cherrypicks//build/../gcc/gcc-4.4.3/libgcc/../gcc/unwind-dw2-fde.c:726
  #3  0x080b1f84 in _Unwind_Find_FDE (pc=0x80b10da, bases=0xbfa61204) at /Users/andrewhsieh/ndk-andrewhsieh/src.1-with-cherrypicks//build/../gcc/gcc-4.4.3/libgcc/../gcc/unwind-dw2-fde.c:989
  #4  0x080b07db in uw_frame_state_for (context=&lt;value optimized out&gt;, fs=0xbfa6102c) at /Users/andrewhsieh/ndk-andrewhsieh/src.1-with-cherrypicks//build/../gcc/gcc-4.4.3/libgcc/../gcc/unwind-dw2.c:1128
  #5  0x080b0af8 in uw_init_context_1 (context=0xbfa61230, outer_cfa=&lt;value optimized out&gt;, outer_ra=0x809aa14) at /Users/andrewhsieh/ndk-andrewhsieh/src.1-with-cherrypicks//build/../gcc/gcc-4.4.3/libgcc/../gcc/unwind-dw2.c:1447
  #6  0x080b10db in _Unwind_RaiseException (exc=0x944d060) at /Users/andrewhsieh/ndk-andrewhsieh/src.1-with-cherrypicks//build/../gcc/gcc-4.4.3/libgcc/../gcc/unwind.inc:88
  #7  0x0809aa14 in __cxa_throw ()
  #8  0x0804b4a7 in main () at exceptiontest.cpp:13
  </code></pre>