Index: libcfa/src/exception.c
===================================================================
--- libcfa/src/exception.c	(revision 2a3b019aa0163c7f5574a142e8a058af99a7fa71)
+++ libcfa/src/exception.c	(revision 9cb89b8729329516d0bdd5fc3576f17ad688fcd5)
@@ -58,10 +58,10 @@
     exception_t * current_exception;
     int current_handler_index;
-} shared_stack = {NULL, NULL, 0, 0};
+} static shared_stack = {NULL, NULL, NULL, 0};
 
 // Get the current exception context.
 // There can be a single global until multithreading occurs, then each stack
 // needs its own. It will have to be updated to handle that.
-inline static struct exception_context_t * this_exception_context() {
+struct exception_context_t * this_exception_context() {
 	return &shared_stack;
 }
@@ -162,5 +162,5 @@
 		node = EXCEPT_TO_NODE(context->current_exception);
 		// It may always be in the first or second position.
-		while( to_free != node->next ) {
+		while ( to_free != node->next ) {
 			node = node->next;
 		}
@@ -191,6 +191,6 @@
 		struct _Unwind_Context * unwind_context,
 		void * stop_param) {
-	if( actions & _UA_END_OF_STACK  ) exit(1);
-	if( actions & _UA_CLEANUP_PHASE ) return _URC_NO_REASON;
+	if ( actions & _UA_END_OF_STACK  ) exit(1);
+	if ( actions & _UA_CLEANUP_PHASE ) return _URC_NO_REASON;
 
 	return _URC_FATAL_PHASE2_ERROR;
@@ -215,5 +215,5 @@
 	// the whole stack.
 
-	if( ret == _URC_END_OF_STACK ) {
+	if ( ret == _URC_END_OF_STACK ) {
 		// No proper handler was found. This can be handled in many ways, C++ calls std::terminate.
 		// Here we force unwind the stack, basically raising a cancellation.
@@ -257,5 +257,5 @@
 
 	// If we've reached the end of the stack then there is nothing much we can do...
-	if( actions & _UA_END_OF_STACK ) return _URC_END_OF_STACK;
+	if (actions & _UA_END_OF_STACK) return _URC_END_OF_STACK;
 
 	if (actions & _UA_SEARCH_PHASE) {
@@ -272,7 +272,7 @@
 
 	// Get a pointer to the language specific data from which we will read what we need
-	const unsigned char * lsd = (const unsigned char*) _Unwind_GetLanguageSpecificData( unwind_context );
-
-	if( !lsd ) {	//Nothing to do, keep unwinding
+	const unsigned char * lsd = _Unwind_GetLanguageSpecificData( unwind_context );
+
+	if ( !lsd ) {	//Nothing to do, keep unwinding
 		printf(" no LSD");
 		goto UNWIND;
@@ -287,5 +287,5 @@
 
 	// Linearly search the table for stuff to do
-	while( cur_ptr < lsd_info.action_table ) {
+	while ( cur_ptr < lsd_info.action_table ) {
 		_Unwind_Ptr callsite_start;
 		_Unwind_Ptr callsite_len;
@@ -300,5 +300,5 @@
 
 		// Have we reach the correct frame info yet?
-		if( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) {
+		if ( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) {
 #ifdef __CFA_DEBUG_PRINT__
 			void * ls = (void*)lsd_info.Start;
@@ -315,87 +315,85 @@
 
 		// Have we gone too far?
-		if( lsd_info.Start + callsite_start > instruction_ptr ) {
+		if ( lsd_info.Start + callsite_start > instruction_ptr ) {
 			printf(" gone too far");
 			break;
 		}
 
-		// Something to do?
+		// Check for what we must do:
 		if ( 0 == callsite_landing_pad ) {
 			// Nothing to do, move along
 			__cfaabi_dbg_print_safe(" no landing pad");
-		} else {
-			// Which phase are we in
-			if (actions & _UA_SEARCH_PHASE) {
-				// In search phase, these means we found a potential handler we must check.
-
-				// We have arbitrarily decided that 0 means nothing to do and 1 means there is
-				// a potential handler. This doesn't seem to conflict the gcc default behavior.
-				if (callsite_action != 0) {
-					// Now we want to run some code to see if the handler matches
-					// This is the tricky part where we want to the power to run arbitrary code
-					// However, generating a new exception table entry and try routine every time
-					// is way more expansive than we might like
-					// The information we have is :
-					//  - The GR (Series of registers)
-					//    GR1=GP Global Pointer of frame ref by context
-					//  - The instruction pointer
-					//  - The instruction pointer info (???)
-					//  - The CFA (Canonical Frame Address)
-					//  - The BSP (Probably the base stack pointer)
-
-
-					// The current apprach uses one exception table entry per try block
-					_uleb128_t imatcher;
-					// Get the relative offset to the {...}?
-					cur_ptr = read_uleb128(cur_ptr, &imatcher);
-
-#					if defined( __x86_64 )
-					_Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 8;
-#					elif defined( __i386 )
-					_Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 24;
-#					endif
-					int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos;
-
-					int index = matcher(context->current_exception);
-					_Unwind_Reason_Code ret = (0 == index)
-						? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
-					context->current_handler_index = index;
-
-					// Based on the return value, check if we matched the exception
-					if( ret == _URC_HANDLER_FOUND) {
-						__cfaabi_dbg_print_safe(" handler found\n");
-					} else {
-						__cfaabi_dbg_print_safe(" no handler\n");
-					}
-					return ret;
+		} else if (actions & _UA_SEARCH_PHASE) {
+			// In search phase, these means we found a potential handler we must check.
+
+			// We have arbitrarily decided that 0 means nothing to do and 1 means there is
+			// a potential handler. This doesn't seem to conflict the gcc default behavior.
+			if (callsite_action != 0) {
+				// Now we want to run some code to see if the handler matches
+				// This is the tricky part where we want to the power to run arbitrary code
+				// However, generating a new exception table entry and try routine every time
+				// is way more expansive than we might like
+				// The information we have is :
+				//  - The GR (Series of registers)
+				//    GR1=GP Global Pointer of frame ref by context
+				//  - The instruction pointer
+				//  - The instruction pointer info (???)
+				//  - The CFA (Canonical Frame Address)
+				//  - The BSP (Probably the base stack pointer)
+
+
+				// The current apprach uses one exception table entry per try block
+				_uleb128_t imatcher;
+				// Get the relative offset to the {...}?
+				cur_ptr = read_uleb128(cur_ptr, &imatcher);
+
+#				if defined( __x86_64 )
+				_Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 8;
+#				elif defined( __i386 )
+				_Unwind_Word match_pos = _Unwind_GetCFA(unwind_context) + 24;
+#				endif
+				int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos;
+
+				int index = matcher(context->current_exception);
+				_Unwind_Reason_Code ret = (0 == index)
+					? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
+				context->current_handler_index = index;
+
+				// Based on the return value, check if we matched the exception
+				if (ret == _URC_HANDLER_FOUND) {
+					__cfaabi_dbg_print_safe(" handler found\n");
+				} else {
+					__cfaabi_dbg_print_safe(" no handler\n");
 				}
-
-				// This is only a cleanup handler, ignore it
-				__cfaabi_dbg_print_safe(" no action");
+				return ret;
 			}
-			else if (actions & _UA_CLEANUP_PHASE) {
-
-				if( (callsite_action != 0) && !(actions & _UA_HANDLER_FRAME) ){
-					// If this is a potential exception handler
-					// but not the one that matched the exception in the seach phase,
-					// just ignore it
-					goto UNWIND;
-				}
-
-				// We need to run some clean-up or a handler
-				// These statment do the right thing but I don't know any specifics at all
-				_Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(0),
-					(_Unwind_Ptr)unwind_exception );
-				_Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(1), 0 );
-
-				// I assume this sets the instruction pointer to the adress of the landing pad
-				// It doesn't actually set it, it only state the value that needs to be set once we return _URC_INSTALL_CONTEXT
-				_Unwind_SetIP( unwind_context, ((lsd_info.LPStart) + (callsite_landing_pad)) );
-
-				__cfaabi_dbg_print_safe(" action\n");
-
-				// Return have some action to run
-				return _URC_INSTALL_CONTEXT;
+
+			// This is only a cleanup handler, ignore it
+			__cfaabi_dbg_print_safe(" no action");
+		} else if (actions & _UA_CLEANUP_PHASE) {
+			// In clean-up phase, no destructors here but this could be the handler.
+
+			if ( (callsite_action != 0) && !(actions & _UA_HANDLER_FRAME) ){
+				// If this is a potential exception handler
+				// but not the one that matched the exception in the seach phase,
+				// just ignore it
+				goto UNWIND;
 			}
+
+			// We need to run some clean-up or a handler
+			// These statment do the right thing but I don't know any specifics at all
+			_Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(0),
+				(_Unwind_Ptr)unwind_exception );
+			_Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(1), 0 );
+
+			// I assume this sets the instruction pointer to the adress of the landing pad
+			// It doesn't actually set it, it only state the value that needs to be set once we
+			// return _URC_INSTALL_CONTEXT
+			_Unwind_SetIP( unwind_context, ((lsd_info.LPStart) + (callsite_landing_pad)) );
+
+			__cfaabi_dbg_print_safe(" action\n");
+
+			// Return have some action to run
+			return _URC_INSTALL_CONTEXT;
 		}
 	}
@@ -422,10 +420,8 @@
 	//! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
 
-	// Setup statments: These 2 statments won't actually result in any code, they only setup global tables.
-	// However, they clobber gcc cancellation support from gcc.  We can replace the personality routine but
-	// replacing the exception table gcc generates is not really doable, it generates labels based on how the
-	// assembly works.
-
 	// Setup the personality routine and exception table.
+	// Unforturnately these clobber gcc cancellation support which means we can't get access to
+	// the attribute cleanup tables at the same time. We would have to inspect the assembly to
+	// create a new set ourselves.
 #ifdef __PIC__
 	asm volatile (".cfi_personality 0x9b,CFA.ref.__gcfa_personality_v0");
@@ -452,7 +448,7 @@
 	// Label which defines the end of the area for which the handler is setup.
 	asm volatile (".TRYEND:");
-	// Label which defines the start of the exception landing pad.  Basically what is called when the exception is
-	// caught.  Note, if multiple handlers are given, the multiplexing should be done by the generated code, not the
-	// exception runtime.
+	// Label which defines the start of the exception landing pad. Basically what is called when
+	// the exception is caught. Note, if multiple handlers are given, the multiplexing should be
+	// done by the generated code, not the exception runtime.
 	asm volatile (".CATCH:");
 
