Boost C++ Libraries: Ticket #12400: libunwind fails to detect end-of-stack with boost::context https://svn.boost.org/trac10/ticket/12400 <p> make_fcontext initialises a new stack, but it is making libunwind not to find its termination, presumably because it is initialising it by pointing to a call to program exit. </p> <p> Problematic source: <a class="ext-link" href="https://github.com/boostorg/context/blob/develop/src/asm/make_x86_64_sysv_elf_gas.S"><span class="icon">​</span>https://github.com/boostorg/context/blob/develop/src/asm/make_x86_64_sysv_elf_gas.S</a> </p> <p> leaq -0x40(%rax), %rax moves the stack pointer down 64 bytes The top thing on the stack at the highest address is what the comment calls EXIT, and is a pointer to the finish label. There is nothing after that No frame where RBP is null or an undefine dIP Boost does not put anything after that at all </p> <p> From libunwind sources: file Gstep.c, end-of stack detection algorithm: </p> <p> /* x86_64 ABI specifies that end of call-chain is marked with a NULL RBP or undefined return address */ </p> <blockquote> <p> if (DWARF_IS_NULL_LOC (c-&gt;dwarf.loc[RBP]) </p> <blockquote> <table class="wiki"> <tr><td> DWARF_IS_NULL_LOC(c-&gt;dwarf.loc[c-&gt;dwarf.ret_addr_column])) </td></tr></table> </blockquote> <p> { </p> <blockquote> <p> c-&gt;dwarf.ip = 0; ret = 0; </p> </blockquote> <p> } </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12400 Trac 1.4.3 mmayorga@… Thu, 25 Aug 2016 08:09:25 GMT <link>https://svn.boost.org/trac10/ticket/12400#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12400#comment:1</guid> <description> <p> A patch that solves the issue is: </p> <pre class="wiki">Index: boost_1_56_0/libs/context/src/asm/make_x86_64_sysv_elf_gas.S =================================================================== --- boost_1_56_0.orig/libs/context/src/asm/make_x86_64_sysv_elf_gas.S +++ boost_1_56_0/libs/context/src/asm/make_x86_64_sysv_elf_gas.S @@ -61,6 +61,9 @@ make_fcontext: /* will be entered after context-function returns */ movq %rcx, 0x40(%rax) + /* BP 1st frame to be 0 */ + movq $0, 0x30(%rax) + ret /* return pointer to context-data */ finish: </pre> </description> <category>Ticket</category> </item> <item> <author>mmayorga@…</author> <pubDate>Thu, 25 Aug 2016 08:10:55 GMT</pubDate> <title>keywords, version changed https://svn.boost.org/trac10/ticket/12400#comment:2 https://svn.boost.org/trac10/ticket/12400#comment:2 <ul> <li><strong>keywords</strong> coroutine added </li> <li><strong>version</strong> <span class="trac-field-old">Boost Development Trunk</span> → <span class="trac-field-new">Boost 1.56.0</span> </li> </ul> Ticket mmayorga@… Wed, 14 Sep 2016 13:37:01 GMT <link>https://svn.boost.org/trac10/ticket/12400#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12400#comment:3</guid> <description> <p> movq $0, 0x30(%rax) better implemented using xor rax,rax </p> </description> <category>Ticket</category> </item> <item> <author>mmayorga@…</author> <pubDate>Wed, 14 Sep 2016 13:39:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12400#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12400#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/12400#comment:3" title="Comment 3">mmayorga@…</a>: </p> <blockquote class="citation"> <p> movq $0, 0x30(%rax) better implemented using xor rax,rax </p> </blockquote> <p> I meant movq $0, 0x30(%rax) better implemented using xorq if possible with 0x30(%rax) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Tue, 11 Oct 2016 08:23:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12400#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12400#comment:5</guid> <description> <p> your code seams to be false because RIP (address of context-fn) is stored as RIP in 0x30(%rax). the address of the label 'finish' is stored as the return address for the context-fn (e.g. if the context-fn returns, a branch to label 'finish' happens). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Tue, 11 Oct 2016 12:44:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12400#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12400#comment:6</guid> <description> <p> I've added an example backtraceing the call stack (using libunwind) - seams to work on x86_64. </p> </description> <category>Ticket</category> </item> <item> <author>mmayorga@…</author> <pubDate>Fri, 21 Oct 2016 12:25:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12400#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12400#comment:7</guid> <description> <p> I'll make and upload a reproducer... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Sun, 27 Nov 2016 09:33:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12400#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12400#comment:8</guid> <description> <p> I close this bug report - works for me (example/v2/backtrace.cpp - needs to be enabled in Jamfile.v2). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Sun, 27 Nov 2016 09:34:06 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/12400#comment:9 https://svn.boost.org/trac10/ticket/12400#comment:9 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> Ticket