<div dir="ltr">Sorry it took this long, got pushed down on my TODO list :)<div><br></div><div>Cheers,<br><div><br></div><div>/ Asiri</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 14, 2016 at 5:04 PM, Jonathan Roelofs via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 6/14/16 9:51 AM, Asiri Rathnayake via cfe-commits wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: asiri<br>
Date: Tue Jun 14 10:51:01 2016<br>
New Revision: 272680<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=272680&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=272680&view=rev</a><br>
Log:<br>
[libunwind] Improve unwinder stack usage - III<br>
<br>
Implement the same optimization committed under r271004 on non-EHABI,<br>
non-SJLJ unwinder as well.<br>
</blockquote>
<br></span>
Thanks!<br>
<br>
<br>
Jon<div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Change-Id: I7f80ed91a75d1e778b50ba87cf8fb68658a083c7<br>
<br>
Modified:<br>
libunwind/trunk/src/UnwindLevel1.c<br>
<br>
Modified: libunwind/trunk/src/UnwindLevel1.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindLevel1.c?rev=272680&r1=272679&r2=272680&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/UnwindLevel1.c?rev=272680&r1=272679&r2=272680&view=diff</a><br>
==============================================================================<br>
--- libunwind/trunk/src/UnwindLevel1.c (original)<br>
+++ libunwind/trunk/src/UnwindLevel1.c Tue Jun 14 10:51:01 2016<br>
@@ -33,16 +33,15 @@<br>
#if !_LIBUNWIND_ARM_EHABI<br>
<br>
static _Unwind_Reason_Code<br>
-unwind_phase1(unw_context_t *uc, _Unwind_Exception *exception_object) {<br>
- unw_cursor_t cursor1;<br>
- unw_init_local(&cursor1, uc);<br>
+unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {<br>
+ unw_init_local(cursor, uc);<br>
<br>
// Walk each frame looking for a place to stop.<br>
bool handlerNotFound = true;<br>
while (handlerNotFound) {<br>
// Ask libuwind to get next frame (skip over first which is<br>
// _Unwind_RaiseException).<br>
- int stepResult = unw_step(&cursor1);<br>
+ int stepResult = unw_step(cursor);<br>
if (stepResult == 0) {<br>
_LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): unw_step() reached "<br>
"bottom => _URC_END_OF_STACK\n",<br>
@@ -58,7 +57,7 @@ unwind_phase1(unw_context_t *uc, _Unwind<br>
// See if frame has code to run (has personality routine).<br>
unw_proc_info_t frameInfo;<br>
unw_word_t sp;<br>
- if (unw_get_proc_info(&cursor1, &frameInfo) != UNW_ESUCCESS) {<br>
+ if (unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {<br>
_LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): unw_get_proc_info "<br>
"failed => _URC_FATAL_PHASE1_ERROR\n",<br>
(void *)exception_object);<br>
@@ -70,12 +69,12 @@ unwind_phase1(unw_context_t *uc, _Unwind<br>
char functionBuf[512];<br>
const char *functionName = functionBuf;<br>
unw_word_t offset;<br>
- if ((unw_get_proc_name(&cursor1, functionBuf, sizeof(functionBuf),<br>
+ if ((unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),<br>
&offset) != UNW_ESUCCESS) ||<br>
(frameInfo.start_ip + offset > frameInfo.end_ip))<br>
functionName = ".anonymous.";<br>
unw_word_t pc;<br>
- unw_get_reg(&cursor1, UNW_REG_IP, &pc);<br>
+ unw_get_reg(cursor, UNW_REG_IP, &pc);<br>
_LIBUNWIND_TRACE_UNWINDING(<br>
"unwind_phase1(ex_ojb=%p): pc=0x%" PRIx64 ", start_ip=0x%" PRIx64<br>
", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "\n",<br>
@@ -93,13 +92,13 @@ unwind_phase1(unw_context_t *uc, _Unwind<br>
(void *)exception_object, (void *)(uintptr_t)p);<br>
_Unwind_Reason_Code personalityResult =<br>
(*p)(1, _UA_SEARCH_PHASE, exception_object->exception_class,<br>
- exception_object, (struct _Unwind_Context *)(&cursor1));<br>
+ exception_object, (struct _Unwind_Context *)(cursor));<br>
switch (personalityResult) {<br>
case _URC_HANDLER_FOUND:<br>
// found a catch clause or locals that need destructing in this frame<br>
// stop search and remember stack pointer at the frame<br>
handlerNotFound = false;<br>
- unw_get_reg(&cursor1, UNW_REG_SP, &sp);<br>
+ unw_get_reg(cursor, UNW_REG_SP, &sp);<br>
exception_object->private_2 = (uintptr_t)sp;<br>
_LIBUNWIND_TRACE_UNWINDING(<br>
"unwind_phase1(ex_ojb=%p): _URC_HANDLER_FOUND \n",<br>
@@ -127,9 +126,8 @@ unwind_phase1(unw_context_t *uc, _Unwind<br>
<br>
<br>
static _Unwind_Reason_Code<br>
-unwind_phase2(unw_context_t *uc, _Unwind_Exception *exception_object) {<br>
- unw_cursor_t cursor2;<br>
- unw_init_local(&cursor2, uc);<br>
+unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {<br>
+ unw_init_local(cursor, uc);<br>
<br>
_LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)\n",<br>
(void *)exception_object);<br>
@@ -139,7 +137,7 @@ unwind_phase2(unw_context_t *uc, _Unwind<br>
<br>
// Ask libuwind to get next frame (skip over first which is<br>
// _Unwind_RaiseException).<br>
- int stepResult = unw_step(&cursor2);<br>
+ int stepResult = unw_step(cursor);<br>
if (stepResult == 0) {<br>
_LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): unw_step() reached "<br>
"bottom => _URC_END_OF_STACK\n",<br>
@@ -155,8 +153,8 @@ unwind_phase2(unw_context_t *uc, _Unwind<br>
// Get info about this frame.<br>
unw_word_t sp;<br>
unw_proc_info_t frameInfo;<br>
- unw_get_reg(&cursor2, UNW_REG_SP, &sp);<br>
- if (unw_get_proc_info(&cursor2, &frameInfo) != UNW_ESUCCESS) {<br>
+ unw_get_reg(cursor, UNW_REG_SP, &sp);<br>
+ if (unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {<br>
_LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): unw_get_proc_info "<br>
"failed => _URC_FATAL_PHASE1_ERROR\n",<br>
(void *)exception_object);<br>
@@ -168,7 +166,7 @@ unwind_phase2(unw_context_t *uc, _Unwind<br>
char functionBuf[512];<br>
const char *functionName = functionBuf;<br>
unw_word_t offset;<br>
- if ((unw_get_proc_name(&cursor2, functionBuf, sizeof(functionBuf),<br>
+ if ((unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),<br>
&offset) != UNW_ESUCCESS) ||<br>
(frameInfo.start_ip + offset > frameInfo.end_ip))<br>
functionName = ".anonymous.";<br>
@@ -191,7 +189,7 @@ unwind_phase2(unw_context_t *uc, _Unwind<br>
}<br>
_Unwind_Reason_Code personalityResult =<br>
(*p)(1, action, exception_object->exception_class, exception_object,<br>
- (struct _Unwind_Context *)(&cursor2));<br>
+ (struct _Unwind_Context *)(cursor));<br>
switch (personalityResult) {<br>
case _URC_CONTINUE_UNWIND:<br>
// Continue unwinding<br>
@@ -212,14 +210,14 @@ unwind_phase2(unw_context_t *uc, _Unwind<br>
// We may get control back if landing pad calls _Unwind_Resume().<br>
if (_LIBUNWIND_TRACING_UNWINDING) {<br>
unw_word_t pc;<br>
- unw_get_reg(&cursor2, UNW_REG_IP, &pc);<br>
- unw_get_reg(&cursor2, UNW_REG_SP, &sp);<br>
+ unw_get_reg(cursor, UNW_REG_IP, &pc);<br>
+ unw_get_reg(cursor, UNW_REG_SP, &sp);<br>
_LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): re-entering "<br>
"user code with ip=0x%" PRIx64<br>
", sp=0x%" PRIx64 "\n",<br>
(void *)exception_object, pc, sp);<br>
}<br>
- unw_resume(&cursor2);<br>
+ unw_resume(cursor);<br>
// unw_resume() only returns if there was an error.<br>
return _URC_FATAL_PHASE2_ERROR;<br>
default:<br>
@@ -237,18 +235,17 @@ unwind_phase2(unw_context_t *uc, _Unwind<br>
}<br>
<br>
static _Unwind_Reason_Code<br>
-unwind_phase2_forced(unw_context_t *uc,<br>
+unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,<br>
_Unwind_Exception *exception_object,<br>
_Unwind_Stop_Fn stop, void *stop_parameter) {<br>
- unw_cursor_t cursor2;<br>
- unw_init_local(&cursor2, uc);<br>
+ unw_init_local(cursor, uc);<br>
<br>
// Walk each frame until we reach where search phase said to stop<br>
- while (unw_step(&cursor2) > 0) {<br>
+ while (unw_step(cursor) > 0) {<br>
<br>
// Update info about this frame.<br>
unw_proc_info_t frameInfo;<br>
- if (unw_get_proc_info(&cursor2, &frameInfo) != UNW_ESUCCESS) {<br>
+ if (unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {<br>
_LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): unw_step "<br>
"failed => _URC_END_OF_STACK\n",<br>
(void *)exception_object);<br>
@@ -260,7 +257,7 @@ unwind_phase2_forced(unw_context_t *uc,<br>
char functionBuf[512];<br>
const char *functionName = functionBuf;<br>
unw_word_t offset;<br>
- if ((unw_get_proc_name(&cursor2, functionBuf, sizeof(functionBuf),<br>
+ if ((unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),<br>
&offset) != UNW_ESUCCESS) ||<br>
(frameInfo.start_ip + offset > frameInfo.end_ip))<br>
functionName = ".anonymous.";<br>
@@ -276,7 +273,7 @@ unwind_phase2_forced(unw_context_t *uc,<br>
(_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE);<br>
_Unwind_Reason_Code stopResult =<br>
(*stop)(1, action, exception_object->exception_class, exception_object,<br>
- (struct _Unwind_Context *)(&cursor2), stop_parameter);<br>
+ (struct _Unwind_Context *)(cursor), stop_parameter);<br>
_LIBUNWIND_TRACE_UNWINDING(<br>
"unwind_phase2_forced(ex_ojb=%p): stop function returned %d\n",<br>
(void *)exception_object, stopResult);<br>
@@ -296,7 +293,7 @@ unwind_phase2_forced(unw_context_t *uc,<br>
(void *)exception_object, (void *)(uintptr_t)p);<br>
_Unwind_Reason_Code personalityResult =<br>
(*p)(1, action, exception_object->exception_class, exception_object,<br>
- (struct _Unwind_Context *)(&cursor2));<br>
+ (struct _Unwind_Context *)(cursor));<br>
switch (personalityResult) {<br>
case _URC_CONTINUE_UNWIND:<br>
_LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "<br>
@@ -311,7 +308,7 @@ unwind_phase2_forced(unw_context_t *uc,<br>
"_URC_INSTALL_CONTEXT\n",<br>
(void *)exception_object);<br>
// We may get control back if landing pad calls _Unwind_Resume().<br>
- unw_resume(&cursor2);<br>
+ unw_resume(cursor);<br>
break;<br>
default:<br>
// Personality routine returned an unknown result code.<br>
@@ -332,7 +329,7 @@ unwind_phase2_forced(unw_context_t *uc,<br>
_Unwind_Action lastAction =<br>
(_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE | _UA_END_OF_STACK);<br>
(*stop)(1, lastAction, exception_object->exception_class, exception_object,<br>
- (struct _Unwind_Context *)(&cursor2), stop_parameter);<br>
+ (struct _Unwind_Context *)(cursor), stop_parameter);<br>
<br>
// Clean up phase did not resume at the frame that the search phase said it<br>
// would.<br>
@@ -346,6 +343,7 @@ _Unwind_RaiseException(_Unwind_Exception<br>
_LIBUNWIND_TRACE_API("_Unwind_RaiseException(ex_obj=%p)\n",<br>
(void *)exception_object);<br>
unw_context_t uc;<br>
+ unw_cursor_t cursor;<br>
unw_getcontext(&uc);<br>
<br>
// Mark that this is a non-forced unwind, so _Unwind_Resume()<br>
@@ -354,12 +352,12 @@ _Unwind_RaiseException(_Unwind_Exception<br>
exception_object->private_2 = 0;<br>
<br>
// phase 1: the search phase<br>
- _Unwind_Reason_Code phase1 = unwind_phase1(&uc, exception_object);<br>
+ _Unwind_Reason_Code phase1 = unwind_phase1(&uc, &cursor, exception_object);<br>
if (phase1 != _URC_NO_REASON)<br>
return phase1;<br>
<br>
// phase 2: the clean up phase<br>
- return unwind_phase2(&uc, exception_object);<br>
+ return unwind_phase2(&uc, &cursor, exception_object);<br>
}<br>
<br>
<br>
@@ -379,14 +377,15 @@ _LIBUNWIND_EXPORT void<br>
_Unwind_Resume(_Unwind_Exception *exception_object) {<br>
_LIBUNWIND_TRACE_API("_Unwind_Resume(ex_obj=%p)\n", (void *)exception_object);<br>
unw_context_t uc;<br>
+ unw_cursor_t cursor;<br>
unw_getcontext(&uc);<br>
<br>
if (exception_object->private_1 != 0)<br>
- unwind_phase2_forced(&uc, exception_object,<br>
+ unwind_phase2_forced(&uc, &cursor, exception_object,<br>
(_Unwind_Stop_Fn) exception_object->private_1,<br>
(void *)exception_object->private_2);<br>
else<br>
- unwind_phase2(&uc, exception_object);<br>
+ unwind_phase2(&uc, &cursor, exception_object);<br>
<br>
// Clients assume _Unwind_Resume() does not return, so all we can do is abort.<br>
_LIBUNWIND_ABORT("_Unwind_Resume() can't return");<br>
@@ -403,6 +402,7 @@ _Unwind_ForcedUnwind(_Unwind_Exception *<br>
_LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)\n",<br>
(void *)exception_object, (void *)(uintptr_t)stop);<br>
unw_context_t uc;<br>
+ unw_cursor_t cursor;<br>
unw_getcontext(&uc);<br>
<br>
// Mark that this is a forced unwind, so _Unwind_Resume() can do<br>
@@ -411,7 +411,7 @@ _Unwind_ForcedUnwind(_Unwind_Exception *<br>
exception_object->private_2 = (uintptr_t) stop_parameter;<br>
<br>
// do it<br>
- return unwind_phase2_forced(&uc, exception_object, stop, stop_parameter);<br>
+ return unwind_phase2_forced(&uc, &cursor, exception_object, stop, stop_parameter);<br>
}<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br>
</blockquote>
<br></div></div><span class="HOEnZb"><font color="#888888">
-- <br>
Jon Roelofs<br>
<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a><br>
CodeSourcery / Mentor Embedded</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>