[PATCH] D136317: Avoid inline optimization for unwind_phase2 and unwind_phase2_forced

xiongji90 via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 22:47:33 PDT 2022


xiongji90 created this revision.
xiongji90 added reviewers: MaskRay, compnerd.
xiongji90 added a project: libunwind.
Herald added subscribers: libcxx-commits, StephenFan.
Herald added a reviewer: libunwind.
Herald added a project: All.
xiongji90 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently, when building libunwind with CET enabled, we will count the number of stack frames skipped in unwind process and adjust CET shadow stack based on this number. The logic is implemented in unwind_phase2 and unwind_phase2_forced functions and these 2 functions are called by _Unwind_RaiseException and _Unwind_ForcedUnwind.
However, when counting the number of stack frames skipped, current implementation assumes "unwind_phase2" and "unwind_phase2_forced" are not inline optimized, otherwise the number of stack frames must be changed. The assumption may be incorrect when compiler inlines these 2 functions, this patch adds "__attribute__((noinline))" for unwind_phase2 and unwind_phase2.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136317

Files:
  libunwind/src/UnwindLevel1.c


Index: libunwind/src/UnwindLevel1.c
===================================================================
--- libunwind/src/UnwindLevel1.c
+++ libunwind/src/UnwindLevel1.c
@@ -167,7 +167,11 @@
 }
 extern int __unw_step_stage2(unw_cursor_t *);
 
+#if defined(_LIBUNWIND_USE_CET)
+static _Unwind_Reason_Code __attribute__((noinline))
+#else
 static _Unwind_Reason_Code
+#endif
 unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {
   __unw_init_local(cursor, uc);
 
@@ -286,7 +290,11 @@
   return _URC_FATAL_PHASE2_ERROR;
 }
 
+#if defined(_LIBUNWIND_USE_CET)
+static _Unwind_Reason_Code __attribute__((noinline))
+#else
 static _Unwind_Reason_Code
+#endif
 unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
                      _Unwind_Exception *exception_object,
                      _Unwind_Stop_Fn stop, void *stop_parameter) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136317.469115.patch
Type: text/x-patch
Size: 884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221020/919c5459/attachment.bin>


More information about the llvm-commits mailing list