-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Initial support for loongarch64-unknown-linux-gnu #96971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ad26dab
a5e2311
50be2a3
f465bc7
10f7ba5
ccf5417
ca8cad7
b7c5323
737e1d2
bf1758d
a3f0046
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::spec::{Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
Target { | ||
llvm_target: "loongarch64-unknown-linux-gnu".into(), | ||
pointer_width: 64, | ||
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(), | ||
arch: "loongarch64".into(), | ||
options: TargetOptions { | ||
cpu: "generic".into(), | ||
features: "+f,+d".into(), | ||
llvm_abiname: "lp64d".into(), | ||
max_atomic_width: Some(64), | ||
..super::linux_gnu_base::opts() | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,92 @@ | ||||||
# loongarch\*-unknown-linux-\* | ||||||
|
||||||
**Tier: 3** | ||||||
|
||||||
[LoongArch] is a new RISC ISA developed by Loongson Technology Corporation Limited. | ||||||
|
||||||
[LoongArch]: https://loongson.github.io/LoongArch-Documentation/README-EN.html | ||||||
|
||||||
The target name follow this format: `<machine>-<vendor>-<os><fabi_suffix>, where `<machine>` specifies the CPU family/model, `<vendor>` specifies the vendor and `<os>` the operating system name. | ||||||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, Is it better to fix this PR or a new one? thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new PR works better I think given that this PR is already included in a rollup. |
||||||
While the integer base ABI is implied by the machine field, the floating point base ABI type is encoded into the os field of the specifier using the string suffix `<fabi-suffix>`. | ||||||
|
||||||
| `<fabi-suffix>` | `Description` | | ||||||
|------------------------|--------------------------------------------------------------------| | ||||||
| f64 | The base ABI use 64-bits FPRs for parameter passing.(lp64d)| | ||||||
| f32 | The base ABI uses 32-bit FPRs for parameter passing. (lp64f)| | ||||||
| sf | The base ABI uses no FPR for parameter passing. (lp64s) | | ||||||
|
||||||
|`ABI type(Base ABI/ABI extension)`| `C library` | `kernel` | `target tuple` | | ||||||
|----------------------------------|-------------|----------|----------------------------------| | ||||||
| lp64d/base | glibc | linux | loongarch64-unknown-linux-gnu | | ||||||
| lp64f/base | glibc | linux | loongarch64-unknown-linux-gnuf32 | | ||||||
| lp64s/base | glibc | linux | loongarch64-unknown-linux-gnusf | | ||||||
| lp64d/base | musl libc | linux | loongarch64-unknown-linux-musl| | ||||||
| lp64f/base | musl libc | linux | loongarch64-unknown-linux-muslf32| | ||||||
| lp64s/base | musl libc | linux | loongarch64-unknown-linux-muslsf | | ||||||
|
||||||
## Target maintainers | ||||||
|
||||||
- [ZHAI xiaojuan](https://github.com/zhaixiaojuan) `[email protected]` | ||||||
- [WANG rui](https://github.com/heiher) `[email protected]` | ||||||
- [ZHAI xiang](https://github.com/xiangzhai) `[email protected]` | ||||||
- [WANG Xuerui](https://github.com/xen0n) `[email protected]` | ||||||
|
||||||
## Requirements | ||||||
|
||||||
This target is cross-compiled. | ||||||
A GNU toolchain for LoongArch target is required. It can be downloaded from https://github.com/loongson/build-tools/releases, or built from the source code of GCC (12.1.0 or later) and Binutils (2.40 or later). | ||||||
|
||||||
## Building the target | ||||||
|
||||||
The target can be built by enabling it for a `rustc` build. | ||||||
|
||||||
```toml | ||||||
[build] | ||||||
target = ["loongarch64-unknown-linux-gnu"] | ||||||
``` | ||||||
|
||||||
Make sure `loongarch64-unknown-linux-gnu-gcc` can be searched from the directories specified in`$PATH`. Alternatively, you can use GNU LoongArch Toolchain by adding the following to `config.toml`: | ||||||
|
||||||
```toml | ||||||
[target.loongarch64-unknown-linux-gnu] | ||||||
# ADJUST THIS PATH TO POINT AT YOUR TOOLCHAIN | ||||||
cc = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc" | ||||||
cxx = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-g++" | ||||||
ar = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-ar" | ||||||
ranlib = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-ranlib" | ||||||
linker = "/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc" | ||||||
``` | ||||||
|
||||||
## Cross-compilation | ||||||
|
||||||
This target can be cross-compiled on a `x86_64-unknown-linux-gnu` host. Cross-compilation on other hosts may work but is not tested. | ||||||
|
||||||
## Testing | ||||||
To test a cross-compiled binary on your build system, install the qemu binary that supports the LoongArch architecture and execute the following commands. | ||||||
```text | ||||||
CC_loongarch64_unknown_linux_gnu=/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc \ | ||||||
CXX_loongarch64_unknown_linux_gnu=/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-g++ \ | ||||||
AR_loongarch64_unknown_linux_gnu=/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc-ar \ | ||||||
CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNUN_LINKER=/TOOLCHAIN_PATH/bin/loongarch64-unknown-linux-gnu-gcc \ | ||||||
# SET TARGET SYSTEM LIBRARY PATH | ||||||
CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNUN_RUNNER="qemu-loongarch64 -L /TOOLCHAIN_PATH/TARGET_LIBRAY_PATH" \ | ||||||
cargo run --target loongarch64-unknown-linux-gnu --release | ||||||
``` | ||||||
Tested on x86 architecture, other architectures not tested. | ||||||
|
||||||
## Building Rust programs | ||||||
|
||||||
Rust does not yet ship pre-compiled artifacts for this target. To compile for this target, you will either need to build Rust with the target enabled (see "Building the target" above), or build your own copy of `std` by using `build-std` or similar. | ||||||
|
||||||
If `rustc` has support for that target and the library artifacts are available, then Rust static libraries can be built for that target: | ||||||
|
||||||
```shell | ||||||
$ rustc --target loongarch64-unknown-linux-gnu your-code.rs --crate-type staticlib | ||||||
$ ls libyour_code.a | ||||||
``` | ||||||
|
||||||
On Rust Nightly it's possible to build without the target artifacts available: | ||||||
|
||||||
```text | ||||||
cargo build -Z build-std --target loongarch64-unknown-linux-gnu | ||||||
``` |
Uh oh!
There was an error while loading. Please reload this page.