[libcxx-commits] [PATCH] D69677: Correctly update isSignalFrame when unwinding the stack via dwarf.

Sterling Augustine via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 31 12:47:08 PDT 2019


saugustine created this revision.
Herald added subscribers: libcxx-commits, christof.
Herald added a reviewer: jfb.
Herald added a project: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69677

Files:
  libunwind/src/DwarfInstructions.hpp
  libunwind/src/UnwindCursor.hpp
  libunwind/src/UnwindLevel1-gcc-ext.c
  libunwind/test/signal_frame.pass.cpp


Index: libunwind/test/signal_frame.pass.cpp
===================================================================
--- /dev/null
+++ libunwind/test/signal_frame.pass.cpp
@@ -0,0 +1,14 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <libunwind.h>
+
+int main(void) {
+  asm(".cfi_signal_frame");
+  unw_cursor_t cursor;
+  unw_context_t uc;
+  unw_getcontext(&uc);
+  unw_init_local(&cursor, &uc);
+  assert(unw_step(&cursor) > 0);
+  assert(unw_is_signal_frame(&cursor));
+  return 0;
+}
Index: libunwind/src/UnwindLevel1-gcc-ext.c
===================================================================
--- libunwind/src/UnwindLevel1-gcc-ext.c
+++ libunwind/src/UnwindLevel1-gcc-ext.c
@@ -221,7 +221,14 @@
 _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,
                                               int *ipBefore) {
   _LIBUNWIND_TRACE_API("_Unwind_GetIPInfo(context=%p)", (void *)context);
-  *ipBefore = 0;
+  int isSignalFrame = __unw_is_signal_frame((unw_cursor_t *)context);
+  // Negative means some kind of error (probably UNW_ENOINFO), but we have no
+  // good way to report that, and this maintains backward compatibility with the
+  // implementation that hard-coded zero in every case, even signal frames.
+  if (isSignalFrame <= 0)
+    *ipBefore = 0;
+  else
+    *ipBefore = 1;
   return _Unwind_GetIP(context);
 }
 
Index: libunwind/src/UnwindCursor.hpp
===================================================================
--- libunwind/src/UnwindCursor.hpp
+++ libunwind/src/UnwindCursor.hpp
@@ -929,7 +929,7 @@
     return DwarfInstructions<A, R>::stepWithDwarf(_addressSpace,
                                               (pint_t)this->getReg(UNW_REG_IP),
                                               (pint_t)_info.unwind_info,
-                                              _registers);
+                                              _registers, _isSignalFrame);
   }
 #endif
 
Index: libunwind/src/DwarfInstructions.hpp
===================================================================
--- libunwind/src/DwarfInstructions.hpp
+++ libunwind/src/DwarfInstructions.hpp
@@ -34,7 +34,7 @@
   typedef typename A::sint_t sint_t;
 
   static int stepWithDwarf(A &addressSpace, pint_t pc, pint_t fdeStart,
-                           R &registers);
+                           R &registers, bool &isSignalFrame);
 
 private:
 
@@ -150,7 +150,8 @@
 
 template <typename A, typename R>
 int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
-                                           pint_t fdeStart, R &registers) {
+                                           pint_t fdeStart, R &registers,
+                                           bool &isSignalFrame) {
   FDE_Info fdeInfo;
   CIE_Info cieInfo;
   if (CFI_Parser<A>::decodeFDE(addressSpace, fdeStart, &fdeInfo,
@@ -196,6 +197,8 @@
       // restoring SP means setting it to CFA.
       newRegisters.setSP(cfa);
 
+      isSignalFrame = cieInfo.isSignalFrame;
+
 #if defined(_LIBUNWIND_TARGET_AARCH64)
       // If the target is aarch64 then the return address may have been signed
       // using the v8.3 pointer authentication extensions. The original


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69677.227324.patch
Type: text/x-patch
Size: 3177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20191031/1fd079fb/attachment.bin>


More information about the libcxx-commits mailing list