Developer's Guide

Guides and Notes on Developing for LoongArch

When developing for non-x86 systems, many may find themselves asking:

Where's the SDK of this device?

Thanks to the efforts of community contributors and Loongson engineers since 2021, most toolchains now have upstream support.

What does this mean?

This means that the process to install various programming toolchains is now similar, if not identical, to the x86 platform - this means installing them is as easy as installing from distro repositories and with single-line command pastes!

TIP

Given that ABI2.0 (“New World”) is used by most community users and developers, this guide focuses solely on introducing installation and configuration procedures for ABI2.0 systems. ABI1.0 (“Old World”) is not covered here. If you are in a scenario where you have to develop for ABI1.0, we recommend reconsidering and confirming that criterion. Should that necessity arise, please refer to the documentation from Loongson Open Source Community (loongnix.cn).


GNU Toolchain

GCC and Binutils officially support LoongArch. They are available directly from your distro's repository, as binaries, or may be built through cross-compilation.

TIP

Note: Later versions of GCC and Binutils introduces enhanced support for LoongArch. Notably, GCC 14 introduced support for LoongArch vector extensions, whereas Binutils 2.41 introduced support for linker relaxation and, later with GCC 16, medium code model (significantly improving compatibility with larger source projects). All these represent critical functional enhancements. As such, please update them to at least the aforementioned versions.

If you intend to release universal binaries for projects or maintain a Linux distribution, please carefully review the relevant specifications and constraints outlined in the Software Development and Build Convention for LoongArch Architectures.

To install GNU toolchain on common Linux distributions and operating systems:

Operating SystemInstallation Procedure
AOSC OSoma install binutils gcc
Arch Linuxsudo pacman -S binutils gcc
Debian and derivatives such as deepin, openKylin and Loongnix 25sudo apt install build-essential
Red Hat-derived distributions such as Fedora LoongArch Remix, openEuler, Anolis OS, OpenCloudOSsudo dnf install binutils gcc

If you do not have a LoongArch device or wish to cross-compile:

Operating SystemInstallation Procedure
AOSC OSoma install gcc+cross-loongarch64
Debian 13 and later, Ubuntu 24.04 and later, and their respective derivativessudo apt install gcc-loongarch64-linux-gnu
Windows and other Linux distributionsPlease install from GitHub repository loongson/build-tools

LLVM Toolchain

LLVM officially supports LoongArch. It is available directly from your distro's repository, as binaries, or may be built through cross-compilation.

TIP

Note: Later versions of LLVM have introduces enhanced support for LoongArch. LLVM 18 introduced support for LoongArch vector extensions. When available, please update to this version or later.

If you intend to release universal binaries for projects or maintain a Linux distribution, please carefully review the relevant specifications and constraints outlined in the Software Development and Build Convention for LoongArch Architectures.

To install LLVM (including Clang) on common Linux distributions and operating systems:

Operating SystemsInstallation Procedure
AOSC OSoma install llvm
Arch Linuxsudo pacman -S clang llvm
Debian and derivatives such as deepin, openKylin and Loongnix 25sudo apt install clang llvm
Red Hat-derived distributions such as Fedora LoongArch Remix, openEuler, Anolis OS, OpenCloudOSsudo dnf install clang llvm

The LLVM toolchain (particularly the Clang compiler) natively supports cross compilation. To cross-compile this toolchain for LoongArch, use LLVM version 17 or later and refer to this article and specify the LoongArch target (e.g., loongarch64-unknown-linux-gnu).

Rust

Rust officially supports LoongArch. It is available directly from your distro's repository, as binaries, or may be built through cross-compilation.

Rust recommends using rustup to install the Rust toolchain:

bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

To install Rust (rustc) and the Cargo package manager on common Linux distributions and operating systems:

Operating SystemInstallation Procedure
AOSC OSoma install rustc
Arch Linuxsudo pacman -S rustc
Debian and derivatives such as deepin, openKylin and Loongnix 25sudo apt install rust-all
Red Hat-derived distributions such as Fedora LoongArch Remix, openEuler, Anolis OS, OpenCloudOSsudo dnf install rust cargo

Node.js

Node.js officially supports LoongArch. It is available directly from your distro's repository, as binaries, or may be built through cross-compilation. Node.js ships LoongArch binaries through the Unofficial Builds project (tagged as the loong64 architecture).

To install Node.js on common Linux distributions and operating systems:

Operating SystemInstallation Procedure
AOSC OSoma install nodejs
Arch Linuxsudo pacman -S nodejs
Debian and derivatives such as deepin, openKylin and Loongnix 25sudo apt install nodejs
Red Hat-derived distributions such as Fedora LoongArch Remix, openEuler, Anolis OS, OpenCloudOSsudo dnf install nodejs

TIP

Many Linux distributions provide multiple versions of Node.js to suit the needs of different applications and projects. Please consult distro documentation and install alternative Node.js versions as needed.

Go

Go officially supports LoongArch. It is available directly from your distro's repository, as binaries, or may be built through cross-compilation. The Go upstream builds LoongArch binaries, which are available from their download page.

To install Go on common Linux distributions and operating systems:

Operating SystemInstallation Procedure
AOSC OSoma install go
Arch Linuxsudo pacman -S go
Debian and derivatives such as deepin, openKylin and Loongnix 25sudo apt install golang
Red Hat-derived distributions such as Fedora LoongArch Remix, openEuler, Anolis OS, OpenCloudOSsudo dnf install golang

Go natively supports cross-compilation. With Go 1.21 or later, follow the instructions outlined in this article and specify the LoongArch target (i.e., GOARCH=loong64) to cross-compile for LoongArch.

Python

Python officially supports LoongArch. It is available directly from your distro's repository, as binaries, or may be built through cross-compilation.

To install Python on common Linux distributions and operating systems:

Operating SystemInstallation Procedure
AOSC OSoma install python-3
Arch Linuxsudo pacman -S python
Debian and derivatives such as deepin, openKylin and Loongnix 25sudo apt install python3
Red Hat-derived distributions such as Fedora LoongArch Remix, openEuler, Anolis OS, OpenCloudOSsudo dnf install python3

TIP

Since LoongArch still lacks definition for a "manylinux" baseline, the official PyPI repository does not host binaries for LoongArch. This means that when installing PyPI modules using pip, the respective modules will be compiled from source and you may need to install C/C++/Rust toolchains as needed.

Loongson Technology hosts a PyPI binary repository for ABI2.0 systems at lpypi.loongnix.cn. You may edit /etc/pip.conf to and specify this as the default repository. alternatively, the loong64 organization on GitHub maintains an independent PyPI binary repository. For configuration procedures, please refer to the organization's README.

.NET

.NET officially supports LoongArch. However, as LoongArch is classified as a “community-supported architecture” within .NET, Microsoft does not ship binary toolchains for LoongArch.

However, .NET toolchain binaries may be obtained through the following channels:

For common Linux distributions, simply download the SDK package with the RID (.NET Runtime Identifier) linux-loongarch64 to obtain the full toolchain (i.e., dotnet-runtime-10.0.1-linux-loongarch64.tar.gz). For instructions on installing the .NET SDK using tar packages, refer to the official .NET documentation.

Cross-Compiling .NET Applications for LoongArch

.NET natively supports cross-compilation and cross-platform publishing. With .NET 9 or later, refer to this article and specify the target RID to publish .NET applications for LoongArch. However, since LoongArch is classified as a “community-supported architecture” for .NET, NuGet.org does not host .NET runtime packages targeting LoongArch, which may cause build failures.

To workaround this issue, you may obtain and deploy all necessary NuGet packages locally. To do so, simply obtain the following files from the toolchain release pages mentioned above (* denotes specific version numbers):

  • Microsoft.AspNetCore.App.Runtime.linux-loongarch64.*.nupkg
  • Microsoft.NETCore.App.Crossgen2.linux-loongarch64.*.nupkg
  • Microsoft.NETCore.App.Host.linux-loongarch64.*.nupkg
  • Microsoft.NETCore.App.Runtime.linux-loongarch64.*.nupkg
  • runtime.linux-loongarch64.Microsoft.DotNet.ILCompiler.*.nupkg

TIP

The distribution provided by loongson-community/dotnet-unofficial-build categorizes the aforementioned files as "release artifacts." Please download this package to obtain the components listed above.

Place the above files in a path that suits your needs (e.g., /data/loongarch64-nupkgs) and follow the instructions in this article to add this directory to your NuGet source list, as shown below:

xml
<packageSources>
    <add key="LoongArch64 Packages" value="/data/loongarch64-nupkgs" />
</packageSources>

You should now be able to cross-compile .NET applications for LoongArch.

Compiling the .NET Toolchain

Compiling the .NET toolchain itself is a relatively involved process. To ease the learning curve, please refer to the CI build scripts used by Loongson Technology. This method utilizes the VMR source distribution package officially recommended by .NET for compilation.

Java

Due to non-technical reasons, Oracle OpenJDK does not currently support LoongArch JIT. To install Java, it is recommended to download binary packages compatible with the "Linux 5.10.0 kernel UAPI" on the Loongson Open Source Community (loongnix.cn) or through your distro's repository.

To install Java on common Linux distributions and operating systems:

Operating SystemInstallation Procedures
AOSC OSoma install openjdk
Arch Linuxsudo pacman -S java-openjdk
Debian and derivatives such as deepin, openKylin and Loongnix 25sudo apt install default-jdk
Red Hat-derived distributions such as Fedora LoongArch Remix, openEuler, Anolis OS, OpenCloudOSsudo dnf install java-latest-openjdk

TIP

Many Linux distributions provide multiple versions of OpenJDK to suit the needs of different applications and projects. Please consult distro documentation and install alternative OpenJDK versions as needed.

Linux Kernel

The Linux Kernel officially supports LoongArch. Generally, Linux distributions based on ABI2.0 utilize the upstream kernel (along with platform-specific workarounds and other patches, see below). However, some commercial distributions ship the 6.6 "longterm" kernel with an extensive set of platform-specific patches.

TIP

The Linux Kernel introduced LoongArch support since version 5.19. However, to fully leverage the hardware capabilities and performance of LoongArch, please use the latest mainline kernel.

Kernel Maintenance Reference

As noted above, newer Linux kernels are generally preferable due to their better support for LoongArch devices. However, as distros may have their own set of rules when it comes to kernel updates, we have assembled the guide below for your reference.

Linux VersionKey Feature Introduced
6.182K2000/2K3000/3B6000M GPIO fixes
6.172K3000/3B6000M On-Chip NIC DWMAC Support; PWM Frequency Modulation Fix
6.162K2000/2K3000/3B6000M SDIO Support
6.143C6000 Family Multiplexing Support
6.123B6000/3C6000 family support (Advanced Extended IRQ model)
6.7Virtualization support
6.4Simultaneous Multi-Threading (SMT) support

Unmerged Patches

Generally, engineers at Loongson Technology and community developers pushes hardware enablement, optimizations, and fixes to the upstream (mainline) kernel. However, due to technical and non-technical reasons, some patches remain unmerged.

The following table lists all known and essential patches maintained by various downstream parties (developers, distribution communities, etc.), for your reference (the patch list below are based on v6.19-rc1 and do not include patches already submitted to the upstream loongarch mailing list):

DescriptionTypeKconfig EntryLinkNotes
PixArt PS/2 DevicesFeatureMOUSE_PS2_PIXART (bool: y/n)1For laptops such as the Tongfang Chaorui L860-T2 and EA EXCELSIOR L71 based on 3A5000 and 3A6000, this patch fixes an issue where the touchpads were misidentified as PS/2 mice, breaking support for gestures and palm detection.
HWMon support (thermal and other forms of hardware monitoring), providing CPU thermal control for the Loongson 3 familyFeatureCPU_HWMON (bool: y/n)1Does not include support for thermal monitoring of the 7A bridge chip; this patch may cause sensors(1) to read incorrect temperature sensors and data on SoC platforms such as 2K3000/3B6000M.
Multi-channel DMA ControllerFeatureN/A1
2K3000/3B6000M SoC CAN-FD BusFeatureCAN_LSCANFD (bool: y/n), CAN_LSCANFD_PLATFORM (tristate: y/m/n)1Must be used together with the patch for multi-channel DMA controller
BPI1000/1001 (“Old World”) firmware supportFeatureN/A1, 2, 3, 4, 5, 6, 7, 8Essential for booting ABI2.0 systems on Lenovo Kaitian M540z, Gooxi 3C5000L quad-socket servers, and certain platforms shipping Kunlun firmware from 2020 to 2022.
PCIe bus speed detection quirk for some 3B6000 and 3C6000 family processors, where PCIe speeds were incorrectly limited to PCIe 1.0WorkaroundN/A1The scope of impact processor steppings/batches is unclear. For details, see the explanation here
Workaround for inoperaable GPIO due to device descriptions that does not comply with the Loongson CPU Unified System Architecture Specification, where GPIO devices were described within gsi_idx_mapWorkaroundN/A1Should not affect 2K3000/3B6000M and later products
Workaround for intermittent driver crashes, resets, and lockups with AMD GCN 1.0–4.0 GPUs on LoongArch platformsWorkaroundN/A1The mechanism behind this fix is unclear (empirical patch); commercial 6.6 kernels like deepin include a more aggressive (yet similarly unexplained) patchset. See this deepin pull request.
Workaround for data errors that on 7A platforms when using AMD “Radeon” graphics drivers (for TeraScale 2 and earlier graphics cards)WorkaroundN/A1, 2, 3Mechanism unknown but effective; patch 3 limits this workaround to MIPS and LoongArch64 platforms (MACH_LOONGSON64)
Register the third PWM controller LOON0006:03 on the 7A2000 bridge as gsgpu_backlight in board-level ACPI initialization code to support LoongGPU backlight controlWorkaroundN/A1Prerequisite patch for LoongGPU backlight support. For LoongGPU driver-related patches, please refer to AOSC-Tracking/loonggpu-kernel-dkms @ aosc/v1.0.1-alpha-lnd25.5.
Enable "Remote Wake" support for USB root hubs (such as USB keyboards, mice, and other input devices)WorkaroundN/A1, 2Applying this patch enables keyboard wake-up for LoongArch devices in ACPI S3 (suspend-to-RAM), but it is known to prevent some x86 laptops from entering sleep mode. Patch 2 limits this wrokaroun to MIPS and LoongArch64 platforms (MACH_LOONGSON64).

Docker

Docker (utility) now officially supports LoongArch, usually available from your distro's repository.

To install Docker on common Linux distributions and operating systems:

Operating SystemInstallation Method
AOSC OSoma install docker
Arch Linuxsudo pacman -S docker
Debian and derivatives such as deepin, openKylin and Loongnix 25sudo apt install docker.io
Red Hat-derived distributions such as Fedora LoongArch Remix, openEuler, Anolis OS, OpenCloudOSsudo dnf install docker

TIP

There are only few LoongArch containers available in the official Docker registry. Loongson Technology maintains a Docker image repository targeting LoongArch ABI2.0. You can modify your Docker configuration to utilize this registry as needed.

CI Runners

Many code hosting platforms offer CI runner support and some already supports LoongArch natively

GitHub Actions

GitHub Actions Runner could not produce binary releases due to NuGet lacking LoongArch support. If you wish to compile and deploy this CI agent yourself, please refer to this pull request.

GitLab Runner

GitLab Runner officially supports LoongArch. To deploy, simply download and install packages or compressed archives tagged loong64 from its release page.

Gitea act_runner

Gitea act_runner officially supports LoongArch, though LoongArch binaries are not yet available. For now, you may clone the source code to compile and deploy this runner.

Forgejo Runner

Forgejo Runner has not yet merged LoongArch support. If you wish to compile and deploy this runner yourself, please refer to this pull request.

Sourcehut

Sourcehut's CI proxy builds.sr.ht officially supports LoongArch. As this CI runner does not distribute binaries, you would need to build and deploy this runner from source.

Gitee

Gitee has not yet merged LoongArch support. If you wish to compile and deploy this runner yourself, please refer to the following pull requests:

GitCode

As inquired by community members, GitCode currently does not support self-hosted CI proxies and thus it is not possible to support LoongArch, at least for now.