forked from model-checking/verify-rust-std
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#96971 - zhaixiaojuan:master, r=wesleywiser
Initial support for loongarch64-unknown-linux-gnu Hi, We hope to add a new port in rust for LoongArch. LoongArch intro LoongArch is a RISC style ISA which is independently designed by Loongson Technology in China. It is divided into two versions, the 32-bit version (LA32) and the 64-bit version (LA64). LA64 applications have application-level backward binary compatibility with LA32 applications. LoongArch is composed of a basic part (Loongson Base) and an expanded part. The expansion part includes Loongson Binary Translation (LBT), Loongson VirtualiZation (LVZ), Loongson SIMD EXtension (LSX) and Loongson Advanced SIMD EXtension(LASX). Currently the LA464 processor core supports LoongArch ISA and the Loongson 3A5000 processor integrates 4 64-bit LA464 cores. LA464 is a four-issue 64-bit high-performance processor core. It can be used as a single core for high-end embedded and desktop applications, or as a basic processor core to form an on-chip multi-core system for server and high-performance machine applications. Documentations: ISA: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html ABI: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html More docs can be found at: https://loongson.github.io/LoongArch-Documentation/README-EN.html Since last year, we have locally adapted two versions of rust, rust1.41 and rust1.57, and completed the test locally. I'm not sure if I'm submitting all the patches at once, so I split up the patches and here's one of the commits
- Loading branch information
Showing
21 changed files
with
150 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
compiler/rustc_target/src/spec/loongarch64_unknown_linux_gnu.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters