-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add new Tier-3 targets: loongarch64-unknown-none*
#112310
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
compiler/rustc_target/src/spec/loongarch64_unknown_none.rs
This file contains hidden or 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,23 @@ | ||
use super::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy}; | ||
use super::{Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
Target { | ||
llvm_target: "loongarch64-unknown-none".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(), | ||
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::No), | ||
llvm_abiname: "lp64d".into(), | ||
max_atomic_width: Some(64), | ||
position_independent_executables: true, | ||
static_position_independent_executables: true, | ||
panic_strategy: PanicStrategy::Abort, | ||
code_model: Some(CodeModel::Small), | ||
..Default::default() | ||
}, | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
compiler/rustc_target/src/spec/loongarch64_unknown_none_softfloat.rs
This file contains hidden or 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,24 @@ | ||
use super::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy}; | ||
use super::{Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
Target { | ||
llvm_target: "loongarch64-unknown-none-softfloat".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(), | ||
abi: "softfloat".into(), | ||
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::No), | ||
llvm_abiname: "lp64s".into(), | ||
max_atomic_width: Some(64), | ||
position_independent_executables: true, | ||
static_position_independent_executables: true, | ||
panic_strategy: PanicStrategy::Abort, | ||
code_model: Some(CodeModel::Small), | ||
..Default::default() | ||
}, | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,79 @@ | ||
# `loongarch*-unknown-none*` | ||
heiher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
**Tier: 3** | ||
|
||
Freestanding/bare-metal LoongArch64 binaries in ELF format: firmware, kernels, etc. | ||
|
||
| Target | Descriptions | | ||
|------------------------------------|-------------------------------------------------------| | ||
| loongarch64-unknown-none | LoongArch 64-bit, LP64D ABI (freestanding, hardfloat) | | ||
| loongarch64-unknown-none-softfloat | LoongArch 64-bit, LP64S ABI (freestanding, softfloat) | | ||
|
||
## Target maintainers | ||
|
||
- [WANG Rui](https://github.com/heiher) `[email protected]` | ||
- [WANG Xuerui](https://github.com/xen0n) `[email protected]` | ||
|
||
## Requirements | ||
|
||
This target is cross-compiled. There is no support for `std`. There is no | ||
default allocator, but it's possible to use `alloc` by supplying an allocator. | ||
|
||
This allows the generated code to run in environments, such as kernels, which | ||
may need to avoid the use of such registers or which may have special considerations | ||
about the use of such registers (e.g. saving and restoring them to avoid breaking | ||
userspace code using the same registers). You can change code generation to use | ||
additional CPU features via the `-C target-feature=` codegen options to rustc, or | ||
via the `#[target_feature]` mechanism within Rust code. | ||
|
||
By default, code generated with this target should run on any `loongarch` | ||
hardware; enabling additional target features may raise this baseline. | ||
|
||
Code generated with this target will use the `small` code model by default. | ||
You can change this using the `-C code-model=` option to rustc. | ||
|
||
On `loongarch64-unknown-none*`, `extern "C"` uses the [standard calling | ||
convention](https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html). | ||
|
||
This target generates binaries in the ELF format. Any alternate formats or | ||
special considerations for binary layout will require linker options or linker | ||
scripts. | ||
|
||
## Building the target | ||
|
||
You can build Rust with support for the target by adding it to the `target` | ||
list in `config.toml`: | ||
|
||
```toml | ||
[build] | ||
build-stage = 1 | ||
target = ["loongarch64-unknown-none"] | ||
``` | ||
|
||
## Building Rust programs | ||
|
||
```text | ||
# target flag may be used with any cargo or rustc command | ||
cargo build --target loongarch64-unknown-none | ||
``` | ||
|
||
## Testing | ||
|
||
As `loongarch64-unknown-none*` supports a variety of different environments and does | ||
not support `std`, this target does not support running the Rust test suite. | ||
|
||
## Cross-compilation toolchains and C code | ||
|
||
If you want to compile C code along with Rust (such as for Rust crates with C | ||
dependencies), you will need an appropriate `loongarch` toolchain. | ||
|
||
Rust *may* be able to use an `loongarch64-unknown-linux-gnu-` toolchain with | ||
appropriate standalone flags to build for this toolchain (depending on the assumptions | ||
of that toolchain, see below), or you may wish to use a separate | ||
`loongarch64-unknown-none` toolchain. | ||
|
||
On some `loongarch` hosts that use ELF binaries, you *may* be able to use the host | ||
C toolchain, if it does not introduce assumptions about the host environment | ||
that don't match the expectations of a standalone environment. Otherwise, you | ||
may need a separate toolchain for standalone/freestanding development, just as | ||
when cross-compiling from a non-`loongarch` platform. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.