On 20.05.2014 20:24, Ramana Radhakrishnan wrote:
For now, please revert your original patch and one of Richard or me
will try to look at it in the morning. The thumb1 case is slightly
more complicated than this.
I don't like this approach as you are introducing the problem again in
ARM state
I am not sure, could you provide more details: why do you think ARM
state is invalid here?
and leaving the problem as is for Thumb1.
True. I've came up a new draft implementation which supports also thumb1
(untested). Does it look saner?
Actually, it seems "pop lr" is not really necessary because following by
"bl _Unwind_Resume @ Never returns" instruction overwrites lr immediately.
Perhaps it may make sense to replace "bl _Unwind_Resume" with "b
_Unwind_Resume" to keep backtracing also in _Unwind_Resume?
Best regards,
Merzlyakov Alexey
--- gcc-4_9-vanilla/libstdc++-v3/libsupc++/eh_arm.cc 2014-05-22 17:20:43.018209504 +0400
+++ gcc-4_9/libstdc++-v3/libsupc++/eh_arm.cc 2014-05-22 16:32:43.726271177 +0400
@@ -199,27 +199,51 @@
" nop 5\n");
#else
// Assembly wrapper to call __gnu_end_cleanup without clobbering r1-r3.
-// Also push r4 to preserve stack alignment.
-#ifdef __thumb__
+// Also push lr to preserve stack alignment and to allow backtracing.
+#ifdef __thumb2__
asm (" .pushsection .text.__cxa_end_cleanup\n"
" .global __cxa_end_cleanup\n"
" .type __cxa_end_cleanup, \"function\"\n"
" .thumb_func\n"
"__cxa_end_cleanup:\n"
-" push\t{r1, r2, r3, r4}\n"
+" .fnstart\n"
+" push\t{r1, r2, r3, lr}\n"
+" .save\t{r1, r2, r3, lr}\n"
" bl\t__gnu_end_cleanup\n"
-" pop\t{r1, r2, r3, r4}\n"
+" pop\t{r1, r2, r3, lr}\n"
" bl\t_Unwind_Resume @ Never returns\n"
+" .fnend\n"
+" .popsection\n");
+#elif defined(__thumb__)
+asm (" .pushsection .text.__cxa_end_cleanup\n"
+" .global __cxa_end_cleanup\n"
+" .type __cxa_end_cleanup, \"function\"\n"
+" .thumb_func\n"
+"__cxa_end_cleanup:\n"
+" .fnstart\n"
+" push\t{r1, r2, r3}\n"
+" .save\t{r1, r2, r3}\n"
+" push\t{lr}\n"
+" .save\t{lr}\n"
+" bl\t__gnu_end_cleanup\n"
+" pop\t{r3}\n"
+" mov\tlr, r3\n"
+" pop\t{r1, r2, r3}\n"
+" bl\t_Unwind_Resume @ Never returns\n"
+" .fnend\n"
" .popsection\n");
#else
asm (" .pushsection .text.__cxa_end_cleanup\n"
" .global __cxa_end_cleanup\n"
" .type __cxa_end_cleanup, \"function\"\n"
"__cxa_end_cleanup:\n"
-" stmfd\tsp!, {r1, r2, r3, r4}\n"
+" .fnstart\n"
+" stmfd\tsp!, {r1, r2, r3, lr}\n"
+" .save\t{r1, r2, r3, lr}\n"
" bl\t__gnu_end_cleanup\n"
-" ldmfd\tsp!, {r1, r2, r3, r4}\n"
+" ldmfd\tsp!, {r1, r2, r3, lr}\n"
" bl\t_Unwind_Resume @ Never returns\n"
+" .fnend\n"
" .popsection\n");
#endif
#endif