Index: libcfa/src/exception.c
===================================================================
--- libcfa/src/exception.c	(revision d231700d6ebda52b790c9c45a3fe6bbb1022aec2)
+++ libcfa/src/exception.c	(revision 3b9c674d6b564a0b4f7d960bcd9069290dca19fa)
@@ -248,13 +248,7 @@
 }
 
-#if defined(PIC)
-#warning Exceptions not yet supported when using Position-Independent Code
-__attribute__((noinline))
-void __cfaabi_ehm__try_terminate(void (*try_block)(),
-		void (*catch_block)(int index, exception_t * except),
-		__attribute__((unused)) int (*match_block)(exception_t * except)) {
-	abort();
-}
-#else // PIC
+#pragma GCC push_options
+#pragma GCC optimize("O0")
+
 // This is our personality routine. For every stack frame annotated with
 // ".cfi_personality 0x3,__gcfa_personality_v0" this function will be called twice when unwinding.
@@ -431,6 +425,11 @@
 
 	// Setup the personality routine and exception table.
+#ifdef __PIC__
+	asm volatile (".cfi_personality 0x9b,CFA.ref.__gcfa_personality_v0");
+	asm volatile (".cfi_lsda 0x1b, .LLSDACFA2");
+#else
 	asm volatile (".cfi_personality 0x3,__gcfa_personality_v0");
 	asm volatile (".cfi_lsda 0x3, .LLSDACFA2");
+#endif
 
 	// Label which defines the start of the area for which the handler is setup.
@@ -464,4 +463,55 @@
 // have a single call to the try routine.
 
+#ifdef __PIC__
+#if defined( __i386 ) || defined( __x86_64 )
+asm (
+	// HEADER
+	".LFECFA1:\n"
+	"	.globl	__gcfa_personality_v0\n"
+	"	.section	.gcc_except_table,\"a\",@progbits\n"
+	// TABLE HEADER (important field is the BODY length at the end)
+	".LLSDACFA2:\n"
+	"	.byte	0xff\n"
+	"	.byte	0xff\n"
+	"	.byte	0x1\n"
+	"	.uleb128 .LLSDACSECFA2-.LLSDACSBCFA2\n"
+	// BODY (language specific data)
+	// This uses language specific data and can be modified arbitrarily
+	// We use handled area offset, handled area length,
+	// handler landing pad offset and 1 (action code, gcc seems to use 0).
+	".LLSDACSBCFA2:\n"
+	"	.uleb128 .TRYSTART-__cfaabi_ehm__try_terminate\n"
+	"	.uleb128 .TRYEND-.TRYSTART\n"
+	"	.uleb128 .CATCH-__cfaabi_ehm__try_terminate\n"
+	"	.uleb128 1\n"
+	".LLSDACSECFA2:\n"
+	// TABLE FOOTER
+	"	.text\n"
+	"	.size	__cfaabi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n"
+);
+
+// Somehow this piece of helps with the resolution of debug symbols.
+__attribute__((unused)) static const int dummy = 0;
+
+asm (
+	// Add a hidden symbol which points at the function.
+	"	.hidden	CFA.ref.__gcfa_personality_v0\n"
+	"	.weak	CFA.ref.__gcfa_personality_v0\n"
+	// No clue what this does specifically
+	"	.section	.data.rel.local.CFA.ref.__gcfa_personality_v0,\"awG\",@progbits,CFA.ref.__gcfa_personality_v0,comdat\n"
+	"	.align 8\n"
+	"	.type CFA.ref.__gcfa_personality_v0, @object\n"
+	"	.size CFA.ref.__gcfa_personality_v0, 8\n"
+	"CFA.ref.__gcfa_personality_v0:\n"
+#if defined( __x86_64 )
+	"	.quad __gcfa_personality_v0\n"
+#else // then __i386
+	"   .long __gcfa_personality_v0\n"
+#endif
+);
+#else
+#error Exception Handling: unknown architecture for position independent code.
+#endif // __i386 || __x86_64
+#else // __PIC__
 #if defined( __i386 ) || defined( __x86_64 )
 asm (
@@ -491,6 +541,10 @@
 	"	.size	__cfaabi_ehm__try_terminate, .-__cfaabi_ehm__try_terminate\n"
 	"	.ident	\"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n"
-//	"	.section	.note.GNU-stack,\"x\",@progbits\n"
+	"	.section	.note.GNU-stack,\"x\",@progbits\n"
 );
+#else
+#error Exception Handling: unknown architecture for position dependent code.
 #endif // __i386 || __x86_64
-#endif // PIC
+#endif // __PIC__
+
+#pragma GCC pop_options
