From 45009af643dbece75d3ee615046b25e76a5438e8 Mon Sep 17 00:00:00 2001
From: "Tobias S. Josefowitz" <tobij@tobij.de>
Date: Tue, 16 Oct 2018 22:12:06 +0200
Subject: [PATCH] Compiler [amd64]: Keep stack alignment before calling C code

GCC 8 started to emit movaps instructions with (%RSP) as destination,
leading to GPF in case it was not properly aligned.
---
 src/code/amd64.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/code/amd64.c b/src/code/amd64.c
index 7fdc44f81b..5105d604f2 100644
--- a/src/code/amd64.c
+++ b/src/code/amd64.c
@@ -2394,7 +2394,9 @@ void ins_f_byte(unsigned int b)
      LABEL_C;/* all done, res in RAX */
       /* free value, store result */
       push( P_REG_RAX );
+      sub_reg_imm(P_REG_RSP, 8);	/* Align on 16 bytes. */
       amd64_free_svalue( P_REG_RBX, 0 );
+      add_reg_imm(P_REG_RSP, 8);
       pop( P_REG_RAX );
       mov_reg_mem(P_REG_RAX,    P_REG_RBX, OFFSETOF(svalue, u.integer));
       mov_imm_mem(PIKE_T_INT, P_REG_RBX, OFFSETOF(svalue, tu.t.type));
@@ -2806,8 +2808,10 @@ int amd64_ins_f_jump(unsigned int op, int backward_jump)
       /* SVALUE_PTR optimization */
       mov_mem_reg( sp_reg, -3*sizeof(struct svalue)+8, P_REG_RDX );
       push( P_REG_RDX );
+      sub_reg_imm(P_REG_RSP, 8);	/* Align on 16 bytes. */
       /* Free old value. */
       amd64_free_svalue( P_REG_RDX, 0 );
+      add_reg_imm(P_REG_RSP, 8);
       pop( P_REG_RDX );
 
       /* Assign new value. */
-- 
GitLab