[libunwind] f178a05 - [libunwind] Fix unwind_leaffunction test

Leonard Chan via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 3 11:21:39 PST 2021


Author: Leonard Chan
Date: 2021-12-03T11:21:20-08:00
New Revision: f178a05f220403f2a9d73c7640bfcc7dc2d7be72

URL: https://github.com/llvm/llvm-project/commit/f178a05f220403f2a9d73c7640bfcc7dc2d7be72
DIFF: https://github.com/llvm/llvm-project/commit/f178a05f220403f2a9d73c7640bfcc7dc2d7be72.diff

LOG: [libunwind] Fix unwind_leaffunction test

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.

Differential Revision: https://reviews.llvm.org/D114818

Added: 
    

Modified: 
    libunwind/test/unwind_leaffunction.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libunwind/test/unwind_leaffunction.pass.cpp b/libunwind/test/unwind_leaffunction.pass.cpp
index 2a6d8311e24c7..8ff21dd35449c 100644
--- a/libunwind/test/unwind_leaffunction.pass.cpp
+++ b/libunwind/test/unwind_leaffunction.pass.cpp
@@ -39,11 +39,17 @@ void signal_handler(int signum) {
 }
 
 __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;
 }


        


More information about the cfe-commits mailing list