From 237d41f89e9b6824dcf5785f8d927469142541db Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Mon, 25 Sep 2017 23:24:41 +0000 Subject: [PATCH] Fix handling of uncaught exceptions in a std::terminate() handler on arm. When raising an exception, the unwinder searches for a catch handler and if none is found it should invoke std::terminate() with the uncaught exception as the "current" exception. Before this change, the terminate handler was invoked with no exception as current (abi::__cxa_current_exception_type() returned NULL), because the return value from the unwinder indicated an internal failure in unwinding. It turns out that was because all errors from get_eit_entry() were translated to _URC_FAILURE. Now the error is returned untranslated, which allows _URC_END_OF_STACK to percolate upwards to throw_exception() in libcxxrt. When it sees that return status it properly calls std::terminate() with the uncaught exception installed as the current exception, allowing custom terminate handlers to work with it. --- contrib/gcc/config/arm/unwind-arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/gcc/config/arm/unwind-arm.c b/contrib/gcc/config/arm/unwind-arm.c index fff5fdf288a8..3ec7e561ca2f 100644 --- a/contrib/gcc/config/arm/unwind-arm.c +++ b/contrib/gcc/config/arm/unwind-arm.c @@ -625,8 +625,8 @@ __gnu_Unwind_RaiseException (_Unwind_Control_Block * ucbp, do { /* Find the entry for this routine. */ - if (get_eit_entry (ucbp, saved_vrs.core.r[R_PC]) != _URC_OK) - return _URC_FAILURE; + if ((pr_result = get_eit_entry (ucbp, saved_vrs.core.r[R_PC])) != _URC_OK) + return pr_result; /* Call the pr to decide what to do. */ pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))