Browse Source

arm64: Make sure SP stays aligned by 16

According to the ARMv8 overview document

  However if SP is used as the base register then the value of the stack
  pointer prior to adding any offset must be quadword (16 byte) aligned,
  or else a stack alignment exception will be generated.

This manifests as a bus error on my system.

To resolve this, just save registers two at a time with stp.
Michael Forney 5 years ago
parent
commit
84f1e2950b
1 changed files with 2 additions and 2 deletions
  1. 2 2
      arm64/emit.c

+ 2 - 2
arm64/emit.c

@@ -378,8 +378,8 @@ arm64_emitfn(Fn *fn, FILE *out)
 	if (e->fn->vararg) {
 		for (n=7; n>=0; n--)
 			fprintf(e->f, "\tstr\tq%d, [sp, -16]!\n", n);
-		for (n=7; n>=0; n--)
-			fprintf(e->f, "\tstr\tx%d, [sp, -8]!\n", n);
+		for (n=7; n>=0; n-=2)
+			fprintf(e->f, "\tstp\tx%d, x%d, [sp, -16]!\n", n-1, n);
 	}
 
 	if (e->frame + 16 <= 512)