From 48e8600492ac724b8b4e8e4bf9c2c3c6f573fd96 Mon Sep 17 00:00:00 2001 From: Finn Coffey Date: Wed, 25 Sep 2024 20:06:45 +1000 Subject: [PATCH 1/2] Avoid running cal_push and cal_pop on startup --- source/backends/arm64.d | 6 +++--- source/backends/x86_64.d | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/backends/arm64.d b/source/backends/arm64.d index 404473b..2e5accb 100644 --- a/source/backends/arm64.d +++ b/source/backends/arm64.d @@ -262,6 +262,9 @@ class BackendARM64 : CompilerBackend { output ~= "sub x20, sp, #4096\n"; // 512 cells output ~= "mov x19, x20\n"; + // jump to main + output ~= "b __calmain\n"; + // create functions for interop if (exportSymbols) { output ~= " @@ -275,9 +278,6 @@ class BackendARM64 : CompilerBackend { ret "; } - - // jump to main - output ~= "b __calmain\n"; } override void End() { diff --git a/source/backends/x86_64.d b/source/backends/x86_64.d index 7a483c1..265a179 100644 --- a/source/backends/x86_64.d +++ b/source/backends/x86_64.d @@ -290,6 +290,9 @@ class BackendX86_64 : CompilerBackend { // copy static array constants output ~= "call __copy_arrays\n"; + // jump to main + output ~= "jmp __calmain\n"; + // create functions for interop if (exportSymbols) { output ~= " @@ -304,9 +307,6 @@ class BackendX86_64 : CompilerBackend { ret "; } - - // jump to main - output ~= "jmp __calmain\n"; } override void End() { From a336eca921f64f36879ac4b873555d1c4b84f97d Mon Sep 17 00:00:00 2001 From: Finn Coffey Date: Wed, 25 Sep 2024 20:19:58 +1000 Subject: [PATCH 2/2] Fix possible stack corruption in arm64 C calls --- source/backends/arm64.d | 1 + 1 file changed, 1 insertion(+) diff --git a/source/backends/arm64.d b/source/backends/arm64.d index 2e5accb..41b6d8c 100644 --- a/source/backends/arm64.d +++ b/source/backends/arm64.d @@ -426,6 +426,7 @@ class BackendARM64 : CompilerBackend { output ~= format("ldr x%d, [x19, #-8]!\n", reg); } + output ~= "and sp, x20, ~0xf\n"; output ~= format("bl %s\n", ExternSymbol(word.symbolName)); if (!word.isVoid) {