Patch-Source: https://github.com/dlang/dmd/commit/cd4cf9cde2593d12ad0daa3f3d8eb7100075f05d
--
From cd4cf9cde2593d12ad0daa3f3d8eb7100075f05d Mon Sep 17 00:00:00 2001
From: Xin Wang <wangxin03@loongson.cn>
Date: Mon, 2 Sep 2024 17:44:08 +0800
Subject: [PATCH] druntime: add support for LoongArch64 on musl and libunwind
 Co-authored-by: Celeste <cielesti@protonmail.com>

---
 druntime/src/core/internal/backtrace/libunwind.d | 5 +++++
 druntime/src/core/stdc/fenv.d                    | 8 ++++++++
 druntime/src/core/sys/posix/signal.d             | 5 +++++
 3 files changed, 18 insertions(+)

diff --git a/runtime/druntime/src/core/internal/backtrace/libunwind.d b/runtime/druntime/src/core/internal/backtrace/libunwind.d
index 3378763eee63..b72858ab79cf 100644
--- a/runtime/druntime/src/core/internal/backtrace/libunwind.d
+++ b/runtime/druntime/src/core/internal/backtrace/libunwind.d
@@ -154,5 +154,10 @@ else version (RISCV64) // 32 is not supported
     enum _LIBUNWIND_CONTEXT_SIZE = 64;
     enum _LIBUNWIND_CURSOR_SIZE = 76;
 }
+else version (LoongArch64)
+{
+    enum _LIBUNWIND_CONTEXT_SIZE = 65;
+    enum _LIBUNWIND_CURSOR_SIZE = 77;
+}
 else
     static assert(0, "Platform not supported");
diff --git a/runtime/druntime/src/core/stdc/fenv.d b/runtime/druntime/src/core/stdc/fenv.d
index b9b10aae3d93..ce77d5c1e6b2 100644
--- a/runtime/druntime/src/core/stdc/fenv.d
+++ b/runtime/druntime/src/core/stdc/fenv.d
@@ -432,6 +432,14 @@ else version (CRuntime_Musl)
         }
         alias ushort fexcept_t;
     }
+    else version (LoongArch64)
+    {
+        struct fenv_t
+        {
+            uint __cw;
+        }
+        alias uint fexcept_t;
+    }
     else
     {
         static assert(false, "Architecture not supported.");
diff --git a/runtime/druntime/src/core/sys/posix/signal.d b/runtime/druntime/src/core/sys/posix/signal.d
index ed4ec1270d90..e3d80fb02180 100644
--- a/runtime/druntime/src/core/sys/posix/signal.d
+++ b/runtime/druntime/src/core/sys/posix/signal.d
@@ -2758,6 +2758,11 @@ else version (CRuntime_Musl)
         enum MINSIGSTKSZ = 2048;
         enum SIGSTKSZ    = 8192;
     }
+    else version (LoongArch64)
+    {
+        enum MINSIGSTKSZ = 4096;
+        enum SIGSTKSZ    = 16384;
+    }
     else
         static assert(0, "unimplemented");
 
