[git commit master 1/1] eh: Add alloc/free for dependent exception

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Sun Nov 21 00:23:16 UTC 2010


commit: http://git.uclibc.org/uClibc++/commit/?id=230a42db9254919a1067c6b2fca31d9fccdf5660
branch: http://git.uclibc.org/uClibc++/commit/?id=refs/heads/master

Recent gcc require dependent exceptions.
abi/libsupc/eh_ptr.o: In function
`std::rethrow_exception(std::__exception_ptr::exception_ptr)':
(.text._ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE+0x21):
undefined reference to `__cxa_allocate_dependent_exception'
abi/libsupc/eh_ptr.o: In function
`__gxx_dependent_exception_cleanup(_Unwind_Reason_Code,
_Unwind_Exception*)':
(.text._ZL33__gxx_dependent_exception_cleanup19_Unwind_Reason_CodeP17_Unwind_Exception+0x30):
undefined reference to `__cxa_free_dependent_exception'

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 include/unwind-cxx.h |   46 ++++++++++++++++++++++++++++++++++++++++++----
 src/eh_alloc.cpp     |   20 ++++++++++++++++++--
 2 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/include/unwind-cxx.h b/include/unwind-cxx.h
index ca0b0a6..4a8961a 100644
--- a/include/unwind-cxx.h
+++ b/include/unwind-cxx.h
@@ -45,8 +45,8 @@
 namespace __cxxabiv1
 {
 
-// A C++ exception object consists of a header, which is a wrapper around
-// an unwind object header with additional C++ specific information,
+// A primary C++ exception object consists of a header, which is a wrapper
+// around an unwind object header with additional C++ specific information,
 // followed by the exception object itself.
 
 struct __cxa_exception
@@ -79,6 +79,40 @@ struct __cxa_exception
   _Unwind_Exception unwindHeader;
 };
 
+
+// A dependent C++ exception object consists of a header, which is a wrapper
+// around an unwind object header with additional C++ specific information,
+// followed by the exception object itself.
+struct __cxa_dependent_exception
+{
+  // The primary exception
+  void *primaryException;
+
+  // The C++ standard has entertaining rules wrt calling set_terminate
+  // and set_unexpected in the middle of the exception cleanup process.
+  std::unexpected_handler unexpectedHandler;
+  std::terminate_handler terminateHandler;
+
+  // The caught exception stack threads through here.
+  __cxa_exception *nextException;
+
+  // How many nested handlers have caught this exception.  A negated
+  // value is a signal that this object has been rethrown.
+  int handlerCount;
+
+  // Cache parsed handler data from the personality routine Phase 1
+  // for Phase 2 and __cxa_call_unexpected.
+  int handlerSwitchValue;
+  const unsigned char *actionRecord;
+  const unsigned char *languageSpecificData;
+  _Unwind_Ptr catchTemp;
+  void *adjustedPtr;
+
+  // The generic exception header.  Must be last.
+  _Unwind_Exception unwindHeader;
+};
+
+
 // Each thread in a C++ program has access to a __cxa_eh_globals object.
 struct __cxa_eh_globals
 {
@@ -94,11 +128,15 @@ struct __cxa_eh_globals
 extern "C" __cxa_eh_globals *__cxa_get_globals () throw();
 extern "C" __cxa_eh_globals *__cxa_get_globals_fast () throw();
 
-// Allocate memory for the exception plus the thown object.
+// Allocate memory for the primary exception plus the thrown object.
 extern "C" void *__cxa_allocate_exception(std::size_t thrown_size) throw();
+// Allocate memory for dependent exception.
+extern "C" __cxa_dependent_exception *__cxa_allocate_dependent_exception() throw();
 
-// Free the space allocated for the exception.
+// Free the space allocated for the primary exception.
 extern "C" void __cxa_free_exception(void *thrown_exception) throw();
+// Free the space allocated for the dependent exception.
+extern "C" void __cxa_free_dependent_exception(__cxa_dependent_exception *dependent_exception) throw();
 
 // Throw the exception.
 extern "C" void __cxa_throw (void *thrown_exception,
diff --git a/src/eh_alloc.cpp b/src/eh_alloc.cpp
index 24fdf9e..5098196 100644
--- a/src/eh_alloc.cpp
+++ b/src/eh_alloc.cpp
@@ -28,10 +28,10 @@ namespace __cxxabiv1{
 
 extern "C" void * __cxa_allocate_exception(std::size_t thrown_size) throw(){
 	void *retval;
-	//The sizeof crap is required by Itanium ABI because we need to provide space for 
+	//The sizeof crap is required by Itanium ABI because we need to provide space for
 	//accounting information which is implementaion (gcc) specified
 	retval = malloc (thrown_size + sizeof(__cxa_exception));
-	if(0 == retval){
+	if (0 == retval){
 		std::terminate();
 	}
 	memset (retval, 0, sizeof(__cxa_exception));
@@ -42,4 +42,20 @@ extern "C" void __cxa_free_exception(void *vptr) throw(){
 	free( (char *)(vptr) - sizeof(__cxa_exception) );
 }
 
+
+extern "C" __cxa_dependent_exception * __cxa_allocate_dependent_exception() throw(){
+	__cxa_dependent_exception *retval;
+	//The sizeof crap is required by Itanium ABI because we need to provide space for
+	//accounting information which is implementaion (gcc) specified
+	retval = static_cast<__cxa_dependent_exception*>(malloc (sizeof(__cxa_dependent_exception)));
+	if (0 == retval){
+		std::terminate();
+	}
+	memset (retval, 0, sizeof(__cxa_dependent_exception));
+	return retval;
+}
+
+extern "C" void __cxa_free_dependent_exception(__cxa_dependent_exception *vptr) throw(){
+	free( (char *)(vptr) );
+}
 }
-- 
1.7.2.2



More information about the uClibc-cvs mailing list