diff options
-rw-r--r-- | lib/csu/aarch64/crt1.c | 10 | ||||
-rw-r--r-- | libexec/rtld-elf/aarch64/rtld_start.S | 10 |
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/csu/aarch64/crt1.c b/lib/csu/aarch64/crt1.c index 6518e8d..de4455e 100644 --- a/lib/csu/aarch64/crt1.c +++ b/lib/csu/aarch64/crt1.c @@ -58,9 +58,13 @@ __asm(" .text \n" " .align 0 \n" " .globl _start \n" " _start: \n" -" mov x3, x2 \n" /* cleanup */ -" ldr x0, [sp] \n" /* Load argc */ -" add x1, sp, #8 \n" /* load argv */ +/* TODO: Remove this when the kernel correctly aligns the stack */ +" cbnz x0, 1f \n" /* Are we using a new kernel? */ +" mov x0, sp \n" /* No, load the args from sp */ +" and sp, x0, #~0xf \n" /* And align the stack */ +"1: mov x3, x2 \n" /* cleanup */ +" add x1, x0, #8 \n" /* load argv */ +" ldr x0, [x0] \n" /* load argc */ " add x2, x1, x0, lsl #3 \n" /* env is after argv */ " add x2, x2, #8 \n" /* argv is null terminated */ " b __start "); diff --git a/libexec/rtld-elf/aarch64/rtld_start.S b/libexec/rtld-elf/aarch64/rtld_start.S index bc45ac7..e34b172 100644 --- a/libexec/rtld-elf/aarch64/rtld_start.S +++ b/libexec/rtld-elf/aarch64/rtld_start.S @@ -34,10 +34,14 @@ ENTRY(.rtld_start) mov x19, x0 /* Put ps_strings in a callee-saved register */ mov x20, sp /* And the stack pointer */ - sub x8, x20, #16 /* Make room for obj_main & exit proc */ - mov sp, x8 /* Update the stack pointer */ + /* Handle the old style stack */ + /* TODO: Remove this when the kernel correctly aligns the stack */ + cbnz x0, 1f + mov x0, sp /* sp points to the args */ + and sp, x0, #~0xf /* Align the stack as needed */ + +1: sub sp, sp, #16 /* Make room for obj_main & exit proc */ - mov x0, x20 /* Pass the stack we were given to _rtld */ mov x1, sp /* exit_proc */ add x2, x1, #8 /* obj_main */ bl _rtld /* Call the loader */ |