diff --git a/doc/release-notes/rl-2511.section.md b/doc/release-notes/rl-2511.section.md index 1fe5d9bf2b0d..81e3c7d04675 100644 --- a/doc/release-notes/rl-2511.section.md +++ b/doc/release-notes/rl-2511.section.md @@ -5,6 +5,12 @@ - Added `allowVariants` to gate availability of package sets like `pkgsLLVM`, `pkgsMusl`, `pkgsZig`, etc. This option will be removed in a future release. +- The initial work to support native compilation on LoongArch64 has completed, with further changes currently + in preparation. In accordance with the [Software Development and Build Convention for LoongArch Architectures](https://github.com/loongson/la-softdev-convention), + this release sets the default march level to `la64v1.0`, covering the desktop and server processors of 3X5000 + and newer series. However, embedded chips without LSX (Loongson SIMD eXtension), such as 2K0300 SoC, are not + supported. `pkgsCross.loongarch64-linux-embedded` can be used to build software and systems for these platforms. + ## Backward Incompatibilities {#sec-nixpkgs-release-25.11-incompatibilities} diff --git a/lib/systems/architectures.nix b/lib/systems/architectures.nix index 51d3b7a7a5a2..91fc2ef0bbfe 100644 --- a/lib/systems/architectures.nix +++ b/lib/systems/architectures.nix @@ -329,6 +329,39 @@ rec { "avx512" "fma" ]; + # LoongArch64 + # https://github.com/loongson/la-toolchain-conventions + loongarch64 = [ + "fpu64" + ]; + la464 = [ + "fpu64" + "lsx" + "lasx" + ]; + la664 = [ + "fpu64" + "lsx" + "lasx" + "div32" + "frecipe" + "lam-bh" + "lamcas" + "ld-seq-sa" + ]; + "la64v1.0" = [ + "fpu64" + "lsx" + ]; + "la64v1.1" = [ + "fpu64" + "lsx" + "div32" + "frecipe" + "lam-bh" + "lamcas" + "ld-seq-sa" + ]; # other armv5te = [ ]; armv6 = [ ]; @@ -486,6 +519,16 @@ rec { ampere1a = [ "ampere1" ] ++ inferiors.ampere1; ampere1b = [ "ampere1a" ] ++ inferiors.ampere1a; + # LoongArch64 + loongarch64 = [ ]; + "la64v1.0" = [ "loongarch64" ]; + la464 = [ "la64v1.0" ] ++ inferiors."la64v1.0"; + "la64v1.1" = [ "la64v1.0" ] ++ inferiors."la64v1.0"; + la664 = withInferiors [ + "la464" + "la64v1.1" + ]; + # other armv5te = [ ]; armv6 = [ ]; @@ -574,5 +617,7 @@ rec { aesSupport = featureSupport "aes"; fmaSupport = featureSupport "fma"; fma4Support = featureSupport "fma4"; + lsxSupport = featureSupport "lsx"; + lasxSupport = featureSupport "lasx"; }; } diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 7378b3bc5ecb..bfb7a73d547e 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -170,9 +170,17 @@ rec { libc = "newlib"; }; - loongarch64-linux = { + # https://github.com/loongson/la-softdev-convention/blob/master/la-softdev-convention.adoc#10-operating-system-package-build-requirements + loongarch64-linux = lib.recursiveUpdate platforms.loongarch64-multiplatform { config = "loongarch64-unknown-linux-gnu"; }; + loongarch64-linux-embedded = lib.recursiveUpdate platforms.loongarch64-multiplatform { + config = "loongarch64-unknown-linux-gnu"; + gcc = { + arch = "loongarch64"; + strict-align = true; + }; + }; mmix = { config = "mmix-unknown-mmixware"; diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index 2df6f5d731cf..8e3f3621698b 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -572,6 +572,19 @@ rec { }; }; + loongarch64-multiplatform = { + gcc = { + # https://github.com/loongson/la-softdev-convention/blob/master/la-softdev-convention.adoc#10-operating-system-package-build-requirements + arch = "la64v1.0"; + strict-align = false; + # Avoid text sections of large apps exceeding default code model + # Will be default behavior in LLVM 21 and hopefully GCC16 + # https://github.com/loongson-community/discussions/issues/43 + # https://github.com/llvm/llvm-project/pull/132173 + cmodel = "medium"; + }; + }; + # This function takes a minimally-valid "platform" and returns an # attrset containing zero or more additional attrs which should be # included in the platform in order to further elaborate it. @@ -607,6 +620,8 @@ rec { else if platform.parsed.cpu == lib.systems.parse.cpuTypes.powerpc64le then powernv + else if platform.isLoongArch64 then + loongarch64-multiplatform else { }; } diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index b9df3fc1b2b0..22109523d312 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -199,6 +199,14 @@ let znver3 = versionAtLeast ccVersion "11.0"; znver4 = versionAtLeast ccVersion "13.0"; znver5 = versionAtLeast ccVersion "14.0"; + + # LoongArch64 + # https://gcc.gnu.org/gcc-12/changes.html#loongarch + # la464 was added together with loongarch64 support + # https://gcc.gnu.org/gcc-14/changes.html#loongarch + "la64v1.0" = versionAtLeast ccVersion "14.0"; + "la64v1.1" = versionAtLeast ccVersion "14.0"; + la664 = versionAtLeast ccVersion "14.0"; } .${arch} or true else if isClang then @@ -223,6 +231,14 @@ let znver3 = versionAtLeast ccVersion "12.0"; znver4 = versionAtLeast ccVersion "16.0"; znver5 = versionAtLeast ccVersion "19.1"; + + # LoongArch64 + # https://releases.llvm.org/16.0.0/tools/clang/docs/ReleaseNotes.html#loongarch-support + # la464 was added together with loongarch64 support + # https://releases.llvm.org/19.1.0/tools/clang/docs/ReleaseNotes.html#loongarch-support + "la64v1.0" = versionAtLeast ccVersion "19.1"; + "la64v1.1" = versionAtLeast ccVersion "19.1"; + la664 = versionAtLeast ccVersion "19.1"; } .${arch} or true else @@ -316,7 +332,17 @@ let ++ optional (targetPlatform ? gcc.fpu) "-mfpu=${targetPlatform.gcc.fpu}" ++ optional (targetPlatform ? gcc.mode) "-mmode=${targetPlatform.gcc.mode}" ++ optional (targetPlatform ? gcc.thumb) "-m${thumb}" - ++ optional (tune != null) "-mtune=${tune}"; + ++ optional (tune != null) "-mtune=${tune}" + ++ + optional (targetPlatform ? gcc.strict-align) + "-m${optionalString (!targetPlatform.gcc.strict-align) "no-"}strict-align" + ++ optional ( + targetPlatform ? gcc.cmodel + && + # TODO: clang on powerpcspe also needs a condition: https://github.com/llvm/llvm-project/issues/71356 + # https://releases.llvm.org/18.1.6/tools/clang/docs/ReleaseNotes.html#loongarch-support + ((targetPlatform.isLoongArch64 && isClang) -> versionAtLeast ccVersion "18.1") + ) "-mcmodel=${targetPlatform.gcc.cmodel}"; defaultHardeningFlags = bintools.defaultHardeningFlags or [ ];