Skip to content

Conversation

@hstk30-hw
Copy link
Contributor

Since insns are always stored LE, on a BE system the opcodes will be loaded byte-reversed. Therefore, define two sets of opcodes, one for LE and one for BE.

@hstk30-hw hstk30-hw requested a review from a team as a code owner November 8, 2025 13:30
@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2025

@llvm/pr-subscribers-libunwind

Author: None (hstk30-hw)

Changes

Since insns are always stored LE, on a BE system the opcodes will be loaded byte-reversed. Therefore, define two sets of opcodes, one for LE and one for BE.


Full diff: https://github.com/llvm/llvm-project/pull/167139.diff

1 Files Affected:

  • (modified) libunwind/src/UnwindCursor.hpp (+9-1)
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 7ec5f9e91578a..9414fd8a81525 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -58,6 +58,14 @@
 #include "RWMutex.hpp"
 #include "Unwind-EHABI.h"
 
+#if defined(__AARCH64EB__)
+#define MOVZ_X8_8B 0x681180d2
+#define SVC_0 0x010000d4
+#else
+#define MOVZ_X8_8B 0xd2801168
+#define SVC_0 0xd4000001
+#endif
+
 #if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
 // Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and
 // earlier) SDKs.
@@ -2827,7 +2835,7 @@ bool UnwindCursor<A, R>::setInfoForSigReturn(Registers_arm64 &) {
     return false;
   auto *instructions = reinterpret_cast<const uint32_t *>(pc);
   // Look for instructions: mov x8, #0x8b; svc #0x0
-  if (instructions[0] != 0xd2801168 || instructions[1] != 0xd4000001)
+  if (instructions[0] != MOVZ_X8_8B || instructions[1] != SVC_0)
     return false;
 
   _info = {};

@ajordanr-google
Copy link
Contributor

This LGTM, and is simple enough, though I shouldn't be an authoritative reviewer on this. @rprichard hopefully can give a more proper review.

Copy link
Contributor

@rprichard rprichard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me too.

I'm wondering to what extent libunwind can be used to unwind a non-native architecture.

@hstk30-hw
Copy link
Contributor Author

I'm wondering to what extent libunwind can be used to unwind a non-native architecture.

This patch only affects the native architecture.
SigReturn function is wrapped by macro _LIBUNWIND_TARGET_LINUX and _LIBUNWIND_TARGET_XX,
which controled by _LIBUNWIND_IS_NATIVE_ONLY.

@hstk30-hw hstk30-hw merged commit 6214dcc into llvm:main Nov 15, 2025
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants