<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW " title="NEW --- - Wrong code for saving registers on ARM" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24331&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=fq2w5YOuqvLDi3kLrra-cww86PhPkBVshbjrBclaD1A&s=Xhbn9x5A_OHpazs0e7ieDCc4AVmb0JOW60jCqsmNDCw&e=">24331</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong code for saving registers on ARM
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++abi
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>manuel.freiberger@gmx.at
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello,

The function unw_getcontext() implemented in the file UnwindRegistersSave.S has
a wrong instruction in line 304:
    stm r0!, {r0-r7}
As a write-back on R0 is used here, the offsets for the instructions in line
307-309 are wrong. The code should be changed to
    stm r0, {r0-r7}
i.e. register R0 should not be modified, similar to the code in the lines
314--317. 

I have tested this on a Cortex-M4. Before making the modification, backtraces 
with libunwind were not working because the PC register was always zero when
unw_step() was called. After the modification everything was fine.

/Manuel

--- UnwindRegistersSave.S       2015-08-01 15:35:38.847465964 +0200
+++ UnwindRegistersSave.S_modified      2015-08-01 15:35:57.105379894 +0200
@@ -301,7 +301,7 @@
   .p2align 2
 DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
 #if !defined(__ARM_ARCH_ISA_ARM)
-  stm r0!, {r0-r7}
+  stm r0, {r0-r7}
   mov r2, sp
   mov r3, lr
   str r2, [r0, #52]</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>