From 04561dac191c0c037108cee9323eb48bd24d25fa Mon Sep 17 00:00:00 2001 From: Ayrton Munoz Date: Mon, 6 Jan 2025 22:34:18 -0500 Subject: [PATCH 1/2] Align initial stack pointers to 16 bytes --- runtime/libia2/init.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/runtime/libia2/init.c b/runtime/libia2/init.c index 7438929cf..b91ef7a66 100644 --- a/runtime/libia2/init.c +++ b/runtime/libia2/init.c @@ -28,12 +28,15 @@ char *allocate_stack(int i) { exit(-1); } } -#ifdef __aarch64__ +#if defined(__aarch64__) /* Tag the allocated stack pointer so it is accessed with the right pkey */ stack = (char *)((uint64_t)stack | (uint64_t)i << 56); -#endif + // TODO: can we do this on x86 too? + return stack + STACK_SIZE - 16; +#else /* Each stack frame start + 8 is initially 16-byte aligned. */ return stack + STACK_SIZE - 8; +#endif } void allocate_stack_0() { From 56b92f9c81c9c89095da130bf048694935dcb183 Mon Sep 17 00:00:00 2001 From: Ayrton Munoz Date: Mon, 6 Jan 2025 22:50:45 -0500 Subject: [PATCH 2/2] Align stack before calling init_tls_N on ARM --- runtime/libia2/include/ia2_internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/libia2/include/ia2_internal.h b/runtime/libia2/include/ia2_internal.h index df6bb854d..7f61fa335 100644 --- a/runtime/libia2/include/ia2_internal.h +++ b/runtime/libia2/include/ia2_internal.h @@ -271,12 +271,12 @@ asm(".macro movz_shifted_tag_x18 tag\n" "mov x9, sp\n" \ /* switch to newly allocated stack */ \ "mov sp, %0\n" \ - /* push old stack pointer to new stack */ \ - "str x9, [sp], #-8\n" \ + /* push the stack pointer in x9 and a dummy reg to new stack */ \ + "stp x9, x10, [sp, #-16]!\n" \ /* initialize TLS */ \ "bl init_tls_" #i "\n" \ /* pop old stack pointer from new stack */ \ - "ldr x9, [sp, #8]!\n" \ + "ldp x9, x10, [sp], #16\n" \ /* save pointer to new stack */ \ "mov x10, sp\n" \ /* switch to old stack */ \