[libcxx-commits] [PATCH] D115020: [libunwind] Fix unwind_leaffunction.pass.cpp

Leonard Chan via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 2 19:06:16 PST 2021


leonardchan created this revision.
leonardchan added reviewers: danielkiss, vvereschaka.
leonardchan added a project: libunwind.
Herald added subscribers: libcxx-commits, pengfei, kristof.beyls.
Herald added a reviewer: libunwind.
leonardchan requested review of this revision.
Herald added a project: LLVM.

It's possible for this test not to pass if the libc used does not provide unwind info for `raise`. We can replace it with `__builtin_cast`, which can lead to a SIGTRAP on x86_64 and a SIGILL on aarch64.

Using this alternative, a `nop` is needed before the `__builtin_cast`. This is because libunwind incorrectly decrements `pc`, which can cause `pc` to jump into the previous function and use the incorrect FDE.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115020

Files:
  libunwind/test/unwind_leaffunction.pass.cpp


Index: libunwind/test/unwind_leaffunction.pass.cpp
===================================================================
--- libunwind/test/unwind_leaffunction.pass.cpp
+++ libunwind/test/unwind_leaffunction.pass.cpp
@@ -39,11 +39,17 @@
 }
 
 __attribute__((noinline)) void crashing_leaf_func(void) {
-  raise(SIGSEGV);
+  // libunwind searches for the address before the return address which points
+  // to the trap instruction. NOP guarantees the trap instruction is not the
+  // first instruction of the function.
+  // We should keep this here for other unwinders that also decrement pc.
+  __asm__ __volatile__("nop");
+  __builtin_trap();
 }
 
 int main(int, char**) {
-  signal(SIGSEGV, signal_handler);
+  signal(SIGTRAP, signal_handler);
+  signal(SIGILL, signal_handler);
   crashing_leaf_func();
   return -2;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115020.391526.patch
Type: text/x-patch
Size: 824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211203/49bb5b77/attachment.bin>


More information about the libcxx-commits mailing list