[PATCH] D78407: [libunwind] Fix ARM EHABI unwinding instruction calculation

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 17 16:59:27 PDT 2020


smeenai created this revision.
smeenai added reviewers: compnerd, danalbert, rprichard, srhines.
Herald added subscribers: libcxx-commits, llvm-commits, danielkiss, kristof.beyls.
Herald added projects: LLVM, libunwind.
Herald added a reviewer: libunwind.

Section 9.3 of the ARM EHABI [1] states that the 01xxxxxx instruction
should be interpreted as follows:

  vsp = vsp - (xxxxxx << 2) - 4

However, libunwind is adding 4 instead of subtracting 4. libgcc's
unwinder follows the spec here, so I'm inclined to believe this is a bug
in libunwind. (Perhaps the intent was to have parentheses around the
expression, such that it was `a - (b + 4)` instead of `a - b + 4`, but
it's hard to say at this point.) Interestingly, this appears to go all
the way back to the initial commit of ARM EHABI unwinding, back in June
2014: https://github.com/llvm/llvm-project/commit/97080e0c5eb4.

[1] https://developer.arm.com/docs/ihi0038/c/exception-handling-abi-for-the-arm-architecture-abi-2018q4-documentation#ehabi32-section9-3


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78407

Files:
  libunwind/src/Unwind-EHABI.cpp


Index: libunwind/src/Unwind-EHABI.cpp
===================================================================
--- libunwind/src/Unwind-EHABI.cpp
+++ libunwind/src/Unwind-EHABI.cpp
@@ -258,7 +258,7 @@
       uint32_t sp;
       _Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32, &sp);
       if (byte & 0x40)
-        sp -= (((uint32_t)byte & 0x3f) << 2) + 4;
+        sp -= (((uint32_t)byte & 0x3f) << 2) - 4;
       else
         sp += ((uint32_t)byte << 2) + 4;
       _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32, &sp);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78407.258446.patch
Type: text/x-patch
Size: 552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200417/607ba681/attachment.bin>


More information about the llvm-commits mailing list