Skip to content

Commit 84c1564

Browse files
authored
[libunwind] Add initial ARM64EC support (#138583)
ARM64EC defines `__x86_64__`, which is sufficient to make most C/C++ code behave correctly. To preserve an external ABI compatible with x86_64, this patch uses the x86_64 context layout and implements `unw_getcontext` by storing the appropriate aarch64 registers according to the mapping defined by the ARM64EC ABI.
1 parent 89826f0 commit 84c1564

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

libunwind/src/UnwindRegistersRestore.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
6666
# skip fs
6767
# skip gs
6868

69-
#elif defined(__x86_64__)
69+
#elif defined(__x86_64__) && !defined(__arm64ec__)
7070

7171
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
7272
#

libunwind/src/UnwindRegistersSave.S

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,47 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
6565
xorl %eax, %eax # return UNW_ESUCCESS
6666
ret
6767

68+
#elif defined(__arm64ec__)
69+
70+
//
71+
// extern int __unw_getcontext(unw_context_t* thread_state)
72+
//
73+
// On entry:
74+
// thread_state pointer is in x0
75+
//
76+
.section .text,"xr",discard,"#__unw_getcontext"
77+
.p2align 2
78+
DEFINE_LIBUNWIND_FUNCTION("#__unw_getcontext")
79+
stp x8, x27, [x0, #0x000] // rax, rbx
80+
stp x0, x1, [x0, #0x010] // rcx, rdx
81+
stp x26,x25, [x0, #0x020] // rdi, rsi
82+
mov x1, sp
83+
stp fp, x1, [x0, #0x030] // rbp, rsp
84+
stp x2, x3, [x0, #0x040] // r8, r9
85+
stp x4, x5, [x0, #0x050] // r10, r11
86+
stp x19,x20, [x0, #0x060] // r12, r13
87+
stp x21,x22, [x0, #0x070] // r14, r15
88+
str x30, [x0, #0x080] // store return address as pc
89+
stp q0, q1, [x0, #0x0b0] // xmm0, xmm1
90+
stp q2, q3, [x0, #0x0d0] // xmm2, xmm3
91+
stp q4, q5, [x0, #0x0f0] // xmm4, xmm5
92+
stp q6, q7, [x0, #0x110] // xmm6, xmm7
93+
stp q8, q9, [x0, #0x130] // xmm8, xmm9
94+
stp q10,q11, [x0, #0x150] // xmm10,xmm11
95+
stp q12,q13, [x0, #0x170] // xmm12,xmm13
96+
stp q14,q15, [x0, #0x190] // xmm14,xmm15
97+
mov x0, #0 // return UNW_ESUCCESS
98+
ret
99+
100+
.weak_anti_dep __unw_getcontext
101+
.set __unw_getcontext, "#__unw_getcontext"
102+
103+
.section .hybmp$x,"yi"
104+
.symidx "#__unw_getcontext"
105+
.symidx $ientry_thunk$cdecl$i8$i8
106+
.word 1
107+
.text
108+
68109
#elif defined(__x86_64__)
69110

70111
#
@@ -1181,7 +1222,15 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
11811222

11821223
#endif
11831224

1225+
#ifdef __arm64ec__
1226+
.globl "#unw_getcontext"
1227+
.set "#unw_getcontext", "#__unw_getcontext"
1228+
.weak_anti_dep unw_getcontext
1229+
.set unw_getcontext, "#unw_getcontext"
1230+
EXPORT_SYMBOL(unw_getcontext)
1231+
#else
11841232
WEAK_ALIAS(__unw_getcontext, unw_getcontext)
1233+
#endif
11851234

11861235
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */
11871236

0 commit comments

Comments
 (0)