Hello, new debdiff pushed on deferred/10

attached.

G.
diff -Nru ldc-1.36.0/debian/changelog ldc-1.36.0/debian/changelog
--- ldc-1.36.0/debian/changelog	2024-02-19 23:46:42.000000000 +0100
+++ ldc-1.36.0/debian/changelog	2024-09-04 00:37:27.000000000 +0200
@@ -1,3 +1,16 @@
+ldc (1:1.36.0-2.1) unstable; urgency=medium
+
+  [ Gianfranco Costamagna ]
+  * Non-maintainer upload.
+  * Cherry-pick 90821fd0bcbcb7d2a652aab9d47f26b6502d9f51 to make PR 4652
+    apply on top of 1.36.0
+
+  [ zhangdandan <zhangdan...@loongson.cn> ]
+  * add build support for loongarch64 (Closes: #1069718)
+  * Cherry-pick upstream PR 4652 to fix loongarch64 support
+
+ -- Gianfranco Costamagna <locutusofb...@debian.org>  Wed, 04 Sep 2024 00:37:27 +0200
+
 ldc (1:1.36.0-2) unstable; urgency=medium
 
   * Only use 64-bit time on armhf
diff -Nru ldc-1.36.0/debian/control ldc-1.36.0/debian/control
--- ldc-1.36.0/debian/control	2024-02-18 22:00:23.000000000 +0100
+++ ldc-1.36.0/debian/control	2024-09-04 00:37:27.000000000 +0200
@@ -27,7 +27,7 @@
 Vcs-Browser: https://salsa.debian.org/d-team/ldc
 
 Package: ldc
-Architecture: amd64 arm64 armhf i386 riscv64
+Architecture: amd64 arm64 armhf i386 riscv64 loong64
 Provides: d-compiler,
           d-v2-compiler
 Depends: libphobos2-ldc-shared-dev (= ${binary:Version}),
@@ -42,7 +42,7 @@
 
 Package: libphobos2-ldc-shared106
 Section: libs
-Architecture: amd64 arm64 armhf i386 riscv64
+Architecture: amd64 arm64 armhf i386 riscv64 loong64
 Multi-Arch: same
 Depends: ${misc:Depends},
          ${shlibs:Depends}
@@ -57,7 +57,7 @@
 
 Package: libphobos2-ldc-shared-dev
 Section: libdevel
-Architecture: amd64 arm64 armhf i386 riscv64
+Architecture: amd64 arm64 armhf i386 riscv64 loong64
 Depends: libphobos2-ldc-shared106 (= ${binary:Version}),
          ${misc:Depends},
          ${shlibs:Depends}
diff -Nru ldc-1.36.0/debian/patches/4652.patch ldc-1.36.0/debian/patches/4652.patch
--- ldc-1.36.0/debian/patches/4652.patch	1970-01-01 01:00:00.000000000 +0100
+++ ldc-1.36.0/debian/patches/4652.patch	2024-09-04 00:37:27.000000000 +0200
@@ -0,0 +1,260 @@
+From ddbe4438c922e42e1d1050d87b526b7f419f10d0 Mon Sep 17 00:00:00 2001
+From: WANG Rui <wang...@loongson.cn>
+Date: Thu, 9 May 2024 20:15:58 +0800
+Subject: [PATCH 1/4] ABI: Fix calling convention for LoongArch
+
+---
+ gen/abi/loongarch64.cpp | 130 +++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 123 insertions(+), 7 deletions(-)
+
+Index: ldc-1.36.0/gen/abi/loongarch64.cpp
+===================================================================
+--- ldc-1.36.0.orig/gen/abi/loongarch64.cpp
++++ ldc-1.36.0/gen/abi/loongarch64.cpp
+@@ -9,7 +9,7 @@
+ //===----------------------------------------------------------------------===//
+ //
+ // ABI spec:
+-// https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
++// https://github.com/loongson/la-abi-specs/blob/release/lapcs.adoc
+ //
+ //===----------------------------------------------------------------------===//
+ 
+@@ -20,9 +20,101 @@
+ #include "gen/llvmhelpers.h"
+ #include "gen/tollvm.h"
+ 
++using namespace dmd;
++
++namespace {
++struct Integer2Rewrite : BaseBitcastABIRewrite {
++  LLType *type(Type *t) override {
++    return LLStructType::get(gIR->context(),
++                             {DtoType(Type::tint64), DtoType(Type::tint64)});
++  }
++};
++
++struct FlattenedFields {
++  Type *fields[2];
++  int length = 0; // use -1 to represent "no need to rewrite" condition
++};
++
++FlattenedFields visitStructFields(Type *ty, unsigned baseOffset) {
++  // recursively visit a POD struct to flatten it
++  FlattenedFields result;
++  if (auto ts = ty->isTypeStruct()) {
++    for (auto fi : ts->sym->fields) {
++      auto sub =
++          visitStructFields(fi->type->toBasetype(), baseOffset + fi->offset);
++      if (sub.length == -1 || result.length + sub.length > 2) {
++        result.length = -1;
++        return result;
++      }
++      for (unsigned i = 0; i < (unsigned)sub.length; ++i) {
++        result.fields[result.length++] = sub.fields[i];
++      }
++    }
++    return result;
++  }
++  switch (ty->ty) {
++  case TY::Tcomplex32: // treat it as {float32, float32}
++    result.fields[0] = pointerTo(Type::tfloat32);
++    result.fields[1] = pointerTo(Type::tfloat32);
++    result.length = 2;
++    break;
++  case TY::Tcomplex64: // treat it as {float64, float64}
++    result.fields[0] = pointerTo(Type::tfloat64);
++    result.fields[1] = pointerTo(Type::tfloat64);
++    result.length = 2;
++    break;
++  default:
++    if (ty->size() > 8) {
++      // field larger than GRLEN and FRLEN
++      result.length = -1;
++      break;
++    }
++    result.fields[0] = ty;
++    result.length = 1;
++    break;
++  }
++  return result;
++}
++
++struct HardfloatRewrite : BaseBitcastABIRewrite {
++  LLType *type(Type *ty, const FlattenedFields &flat) {
++    if (flat.length == 1) {
++      return LLStructType::get(gIR->context(), {DtoType(flat.fields[0])},
++                               false);
++    }
++    assert(flat.length == 2);
++    LLType *t[2];
++    for (unsigned i = 0; i < 2; ++i) {
++      t[i] =
++          flat.fields[i]->isfloating()
++              ? DtoType(flat.fields[i])
++              : LLIntegerType::get(gIR->context(), flat.fields[i]->size() * 8);
++    }
++    return LLStructType::get(gIR->context(), {t[0], t[1]}, false);
++  }
++  LLType *type(Type *ty) override {
++    return type(ty, visitStructFields(ty->toBasetype(), 0));
++  }
++};
++} // anonymous namespace
++
+ struct LoongArch64TargetABI : TargetABI {
+ private:
++  HardfloatRewrite hardfloatRewrite;
+   IndirectByvalRewrite indirectByvalRewrite{};
++  Integer2Rewrite integer2Rewrite;
++  IntegerRewrite integerRewrite;
++
++  bool requireHardfloatRewrite(Type *ty) {
++    if (!isPOD(ty) || !ty->toBasetype()->isTypeStruct())
++      return false;
++    auto result = visitStructFields(ty->toBasetype(), 0);
++    if (result.length <= 0)
++      return false;
++    if (result.length == 1)
++      return result.fields[0]->isfloating();
++    return result.fields[0]->isfloating() || result.fields[1]->isfloating();
++  }
+ 
+ public:
+   auto returnInArg(TypeFunction *tf, bool) -> bool override {
+@@ -45,27 +137,51 @@
+   }
+ 
+   void rewriteFunctionType(IrFuncTy &fty) override {
+-    if (!fty.ret->byref) {
+-      rewriteArgument(fty, *fty.ret);
++    if (!skipReturnValueRewrite(fty)) {
++      if (requireHardfloatRewrite(fty.ret->type)) {
++        // rewrite here because we should not apply this to variadic arguments
++        hardfloatRewrite.applyTo(*fty.ret);
++      } else {
++        rewriteArgument(fty, *fty.ret);
++      }
+     }
+ 
+     for (auto arg : fty.args) {
+       if (!arg->byref) {
+-        rewriteArgument(fty, *arg);
++        if (requireHardfloatRewrite(arg->type)) {
++          // rewrite here because we should not apply this to variadic arguments
++          hardfloatRewrite.applyTo(*arg);
++        } else {
++          rewriteArgument(fty, *arg);
++        }
+       }
+     }
+   }
+ 
+   void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
+-    if (arg.byref) {
+-      return;
+-    }
+-
+     if (!isPOD(arg.type)) {
+       // non-PODs should be passed in memory
+       indirectByvalRewrite.applyTo(arg);
+       return;
+     }
++
++    Type *ty = arg.type->toBasetype();
++    if (ty->isintegral() && (ty->ty == TY::Tint32 || ty->ty == TY::Tuns32 ||
++                             ty->ty == TY::Tdchar)) {
++      // In the LP64D ABI, both int32 and unsigned int32 are stored in
++      // general-purpose registers as proper sign extensions of their
++      // 32-bit values. So, the native ABI function's int32 arguments and
++      // return values should have the `signext` attribute.
++      // C example: https://godbolt.org/z/vcjErxj76
++      arg.attrs.addAttribute(LLAttribute::SExt);
++    } else if (isAggregate(ty) && ty->size() && ty->size() <= 16) {
++      if (ty->size() > 8 && DtoAlignment(ty) < 16) {
++        // pass the aggregate as {int64, int64} to avoid wrong alignment
++        integer2Rewrite.applyToIfNotObsolete(arg);
++      } else {
++        integerRewrite.applyToIfNotObsolete(arg);
++      }
++    }
+   }
+ };
+ 
+Index: ldc-1.36.0/runtime/druntime/src/core/thread/fiber.d
+===================================================================
+--- ldc-1.36.0.orig/runtime/druntime/src/core/thread/fiber.d
++++ ldc-1.36.0/runtime/druntime/src/core/thread/fiber.d
+@@ -229,6 +229,8 @@
+       extern (C) void fiber_switchContext( void** oldp, void* newp ) nothrow @nogc;
+       version (AArch64)
+           extern (C) void fiber_trampoline() nothrow;
++      version (LoongArch64)
++          extern (C) void fiber_trampoline() nothrow;
+   }
+   else version (LDC_Windows)
+   {
+@@ -1828,7 +1830,6 @@
+             // Like others, FP registers and return address ($r1) are kept
+             // below the saved stack top (tstack) to hide from GC scanning.
+             // fiber_switchContext expects newp sp to look like this:
+-            //   10: $r21 (reserved)
+             //    9: $r22 (frame pointer)
+             //    8: $r23
+             //   ...
+@@ -1844,8 +1845,8 @@
+ 
+             // Only need to set return address ($r1).  Everything else is fine
+             // zero initialized.
+-            pstack -= size_t.sizeof * 11;    // skip past space reserved for $r21-$r31
+-            push (cast(size_t) &fiber_entryPoint);
++            pstack -= size_t.sizeof * 10;    // skip past space reserved for $r22-$r31
++            push(cast(size_t) &fiber_trampoline); // see threadasm.S for docs
+             pstack += size_t.sizeof;         // adjust sp (newp) above lr
+         }
+         else version (AsmAArch64_Posix)
+Index: ldc-1.36.0/runtime/druntime/src/core/threadasm.S
+===================================================================
+--- ldc-1.36.0.orig/runtime/druntime/src/core/threadasm.S
++++ ldc-1.36.0/runtime/druntime/src/core/threadasm.S
+@@ -544,9 +544,10 @@
+  */
+  .text
+ .globl fiber_switchContext
++.type  fiber_switchContext, %function
+ fiber_switchContext:
+     .cfi_startproc
+-    .cfi_undefined $ra
++    .cfi_undefined 1
+     # reserve space on stack
+     addi.d  $sp, $sp, -19 * 8
+ 
+@@ -610,6 +611,28 @@
+ 
+     jr $ra
+     .cfi_endproc
++
++/**
++ * When generating any kind of backtrace (gdb, exception handling) for
++ * a function called in a Fiber, we need to tell the unwinder to stop
++ * at our Fiber main entry point, i.e. we need to mark the bottom of
++ * the call stack. This can be done by clearing the return address register $ra
++ * prior to calling fiber_entryPoint (i.e. in fiber_switchContext) or
++ * using a .cfi_undefined directive for the return address register in the
++ * Fiber entry point. cfi_undefined seems to yield better results in gdb.
++ * Unfortunately we can't place it into fiber_entryPoint using inline
++ * asm, so we use this trampoline instead.
++ */
++        .text
++        .global CSYM(fiber_trampoline)
++        .p2align  2
++        .type   fiber_trampoline, %function
++CSYM(fiber_trampoline):
++        .cfi_startproc
++        .cfi_undefined 1
++        // fiber_entryPoint never returns
++        bl CSYM(fiber_entryPoint)
++        .cfi_endproc
+ #elif defined(__arm__) && (defined(__ARM_EABI__) || defined(__APPLE__))
+ /************************************************************************************
+  * ARM ASM BITS
diff -Nru ldc-1.36.0/debian/patches/90821fd0bcbcb7d2a652aab9d47f26b6502d9f51.patch ldc-1.36.0/debian/patches/90821fd0bcbcb7d2a652aab9d47f26b6502d9f51.patch
--- ldc-1.36.0/debian/patches/90821fd0bcbcb7d2a652aab9d47f26b6502d9f51.patch	1970-01-01 01:00:00.000000000 +0100
+++ ldc-1.36.0/debian/patches/90821fd0bcbcb7d2a652aab9d47f26b6502d9f51.patch	2024-09-04 00:37:27.000000000 +0200
@@ -0,0 +1,201 @@
+From 90821fd0bcbcb7d2a652aab9d47f26b6502d9f51 Mon Sep 17 00:00:00 2001
+From: Yang Yujie <yangyu...@loongson.cn>
+Date: Fri, 17 Nov 2023 09:25:47 +0800
+Subject: [PATCH] druntime: adjust LoongArch64 definitions
+
+---
+ runtime/druntime/src/core/stdc/fenv.d         |  8 ++--
+ runtime/druntime/src/core/stdc/stdarg.d       |  6 +++
+ runtime/druntime/src/core/sys/elf/package.d   |  2 +
+ .../druntime/src/core/sys/linux/sys/auxv.d    | 17 +++++++
+ .../druntime/src/core/sys/linux/sys/mman.d    |  1 +
+ runtime/druntime/src/core/thread/fiber.d      | 44 +++++++++++--------
+ runtime/druntime/src/core/vararg.d            |  7 +++
+ 7 files changed, 63 insertions(+), 22 deletions(-)
+
+diff --git a/runtime/druntime/src/core/stdc/fenv.d b/runtime/druntime/src/core/stdc/fenv.d
+index 288f9c25dc6..0051ecdb7c9 100644
+--- a/runtime/druntime/src/core/stdc/fenv.d
++++ b/runtime/druntime/src/core/stdc/fenv.d
+@@ -797,7 +797,7 @@ else
+     }
+     else version (LoongArch64)
+     {
+-        // Define bits representing exceptions in the FPSR status word.
++        // Define bits representing exceptions in the Flags field in FCSR{0,2}.
+         enum
+         {
+             FE_INEXACT      = 0x010000, ///
+@@ -808,13 +808,13 @@ else
+             FE_ALL_EXCEPT   = 0x1f0000, ///
+         }
+ 
+-        // Define bits representing rounding modes in the FPCR Rmode field.
++        // Define bits representing rounding modes in the RM field in FCSR{0,3}.
+         enum
+         {
+             FE_TONEAREST    = 0x000, ///
+             FE_TOWARDZERO   = 0x100, ///
+-            FE_DOWNWARD     = 0x200, ///
+-            FE_UPWARD       = 0x300, ///
++            FE_UPWARD       = 0x200, ///
++            FE_DOWNWARD     = 0x300, ///
+         }
+     }
+     else
+diff --git a/runtime/druntime/src/core/stdc/stdarg.d b/runtime/druntime/src/core/stdc/stdarg.d
+index 5b79813ae1b..0ba1ebe34e3 100644
+--- a/runtime/druntime/src/core/stdc/stdarg.d
++++ b/runtime/druntime/src/core/stdc/stdarg.d
+@@ -257,6 +257,12 @@ T va_arg(T)(ref va_list ap)
+         ap += T.sizeof.alignUp;
+         return *p;
+     }
++    else version (LoongArch64)
++    {
++        auto p = cast(T*) ap;
++        ap += T.sizeof.alignUp;
++        return *p;
++    }
+     else version (MIPS_Any)
+     {
+         auto p = cast(T*) ap;
+diff --git a/runtime/druntime/src/core/sys/elf/package.d b/runtime/druntime/src/core/sys/elf/package.d
+index b120ee58f69..60e05d97036 100644
+--- a/runtime/druntime/src/core/sys/elf/package.d
++++ b/runtime/druntime/src/core/sys/elf/package.d
+@@ -339,6 +339,8 @@ enum EM_CSKY =        252;
+ 
+ enum EM_NUM =         253;
+ 
++enum EM_LOONGARCH =   258;
++
+ enum EM_ALPHA =        0x9026;
+ 
+ enum EV_NONE =         0;
+diff --git a/runtime/druntime/src/core/sys/linux/sys/auxv.d b/runtime/druntime/src/core/sys/linux/sys/auxv.d
+index 5f098e98e02..1099fae497f 100644
+--- a/runtime/druntime/src/core/sys/linux/sys/auxv.d
++++ b/runtime/druntime/src/core/sys/linux/sys/auxv.d
+@@ -13,6 +13,7 @@ extern (C):
+ 
+ version (MIPS32)  version = MIPS_Any;
+ version (MIPS64)  version = MIPS_Any;
++version (LoongArch64) version = LoongArch_Any;
+ version (PPC)     version = PPC_Any;
+ version (PPC64)   version = PPC_Any;
+ version (S390)    version = IBMZ_Any;
+@@ -156,3 +157,19 @@ else version (IBMZ_Any)
+   enum HWCAP_S390_TE                      = 1024;
+   enum HWCAP_S390_VX                      = 2048;
+ }
++else version (LoongArch_Any)
++{
++  enum HWCAP_LOONGARCH_CPUCFG             = 0x00000001;
++  enum HWCAP_LOONGARCH_LAM                = 0x00000002;
++  enum HWCAP_LOONGARCH_UAL                = 0x00000004;
++  enum HWCAP_LOONGARCH_FPU                = 0x00000008;
++  enum HWCAP_LOONGARCH_LSX                = 0x00000010;
++  enum HWCAP_LOONGARCH_LASX               = 0x00000020;
++  enum HWCAP_LOONGARCH_CRC32              = 0x00000040;
++  enum HWCAP_LOONGARCH_COMPLEX            = 0x00000080;
++  enum HWCAP_LOONGARCH_CRYPTO             = 0x00000100;
++  enum HWCAP_LOONGARCH_LVZ                = 0x00000200;
++  enum HWCAP_LOONGARCH_LBT_X86            = 0x00000400;
++  enum HWCAP_LOONGARCH_LBT_ARM            = 0x00000800;
++  enum HWCAP_LOONGARCH_LBT_MIPS           = 0x00001000;
++}
+diff --git a/runtime/druntime/src/core/sys/linux/sys/mman.d b/runtime/druntime/src/core/sys/linux/sys/mman.d
+index 7ed78ef6436..e4765af1490 100644
+--- a/runtime/druntime/src/core/sys/linux/sys/mman.d
++++ b/runtime/druntime/src/core/sys/linux/sys/mman.d
+@@ -432,6 +432,7 @@ else version (MIPS_Any)
+         MAP_HUGETLB = 0x80000,
+     }
+ }
++// http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/mman-map-flags-generic.h
+ else version (LoongArch64)
+ {
+     static if (_DEFAULT_SOURCE) enum
+diff --git a/runtime/druntime/src/core/thread/fiber.d b/runtime/druntime/src/core/thread/fiber.d
+index 1bc5ecbd222..5635088a5f7 100644
+--- a/runtime/druntime/src/core/thread/fiber.d
++++ b/runtime/druntime/src/core/thread/fiber.d
+@@ -128,8 +128,12 @@ private
+     }
+     else version (LoongArch64)
+     {
+-        version = AsmLoongArch64_Posix;
+-        version = AsmExternal;
++        version (Posix)
++        {
++            version = AsmLoongArch64_Posix;
++            version = AsmExternal;
++            version = AlignFiberStackTo16Byte;
++        }
+     }
+ 
+     version (Posix)
+@@ -1393,24 +1397,28 @@ private:
+         }
+         else version (AsmLoongArch64_Posix)
+         {
++            // Like others, FP registers and return address ($r1) are kept
++            // below the saved stack top (tstack) to hide from GC scanning.
++            // fiber_switchContext expects newp sp to look like this:
++            //   10: $r21 (reserved)
++            //    9: $r22 (frame pointer)
++            //    8: $r23
++            //   ...
++            //    0: $r31 <-- newp tstack
++            //   -1: $r1  (return address)  [&fiber_entryPoint]
++            //   -2: $f24
++            //   ...
++            //   -9: $f31
++
+             version (StackGrowsDown) {}
+-            else static assert(0);
++            else
++                static assert(false, "Only full descending stacks supported on LoongArch64");
+ 
+-            // Like others, FP registers and return address (ra) are kept
+-            // below the saved stack top (tstack) to hide from GC scanning.
+-            // The newp stack should look like this on LoongArch64:
+-            // 18: fp     <- pstack
+-            // ...
+-            //  9: s0     <- newp tstack
+-            //  8: ra     [&fiber_entryPoint]
+-            //  7: fs7
+-            // ...
+-            //  1: fs1
+-            //  0: fs0
+-            pstack -= 10 * size_t.sizeof; // skip s0-s8 and fp
+-            // set $ra
+-            push( cast(size_t) &fiber_entryPoint );
+-            pstack += size_t.sizeof;
++            // Only need to set return address ($r1).  Everything else is fine
++            // zero initialized.
++            pstack -= size_t.sizeof * 11;    // skip past space reserved for $r21-$r31
++            push (cast(size_t) &fiber_entryPoint);
++            pstack += size_t.sizeof;         // adjust sp (newp) above lr
+         }
+         else version (AsmAArch64_Posix)
+         {
+diff --git a/runtime/druntime/src/core/vararg.d b/runtime/druntime/src/core/vararg.d
+index 2c3e9659fb6..e6dd47d06d3 100644
+--- a/runtime/druntime/src/core/vararg.d
++++ b/runtime/druntime/src/core/vararg.d
+@@ -129,6 +129,13 @@ void va_arg()(ref va_list ap, TypeInfo ti, void* parmn)
+         ap += tsize.alignUp;
+         parmn[0..tsize] = p[0..tsize];
+     }
++    else version (LoongArch64)
++    {
++        const tsize = ti.tsize;
++        auto p = cast(void*) ap;
++        ap += tsize.alignUp;
++        parmn[0..tsize] = p[0..tsize];
++    }
+     else version (MIPS_Any)
+     {
+         const tsize = ti.tsize;
diff -Nru ldc-1.36.0/debian/patches/series ldc-1.36.0/debian/patches/series
--- ldc-1.36.0/debian/patches/series	2024-02-18 21:04:42.000000000 +0100
+++ ldc-1.36.0/debian/patches/series	2024-09-04 00:37:27.000000000 +0200
@@ -2,3 +2,5 @@
 02_ldc_include_path.diff
 03_ldc-no-default-rpath.patch
 03_pass-NDEBUG-through-LDC_CXXFLAGS.patch
+90821fd0bcbcb7d2a652aab9d47f26b6502d9f51.patch
+4652.patch

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to