|
| 1 | +# `loongarch*-unknown-none*` |
| 2 | + |
| 3 | +**Tier: 3** |
| 4 | + |
| 5 | +Freestanding/bare-metal LoongArch64 binaries in ELF format: firmware, kernels, etc. |
| 6 | + |
| 7 | +| Target | Descriptions | |
| 8 | +|------------------------------------|-------------------------------------------------------| |
| 9 | +| loongarch64-unknown-none | LoongArch 64-bit, LP64D ABI (freestanding, hardfloat) | |
| 10 | +| loongarch64-unknown-none-softfloat | LoongArch 64-bit, LP64S ABI (freestanding, softfloat) | |
| 11 | + |
| 12 | +## Target maintainers |
| 13 | + |
| 14 | +- [WANG Rui ](https://github.com/heiher) `[email protected]` |
| 15 | +- [WANG Xuerui ](https://github.com/xen0n) `[email protected]` |
| 16 | + |
| 17 | +## Requirements |
| 18 | + |
| 19 | +This target is cross-compiled. There is no support for `std`. There is no |
| 20 | +default allocator, but it's possible to use `alloc` by supplying an allocator. |
| 21 | + |
| 22 | +This allows the generated code to run in environments, such as kernels, which |
| 23 | +may need to avoid the use of such registers or which may have special considerations |
| 24 | +about the use of such registers (e.g. saving and restoring them to avoid breaking |
| 25 | +userspace code using the same registers). You can change code generation to use |
| 26 | +additional CPU features via the `-C target-feature=` codegen options to rustc, or |
| 27 | +via the `#[target_feature]` mechanism within Rust code. |
| 28 | + |
| 29 | +By default, code generated with this target should run on any `loongarch` |
| 30 | +hardware; enabling additional target features may raise this baseline. |
| 31 | + |
| 32 | +Code generated with this target will use the `small` code model by default. |
| 33 | +You can change this using the `-C code-model=` option to rustc. |
| 34 | + |
| 35 | +On `loongarch64-unknown-none*`, `extern "C"` uses the [standard calling |
| 36 | +convention](https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html). |
| 37 | + |
| 38 | +This target generates binaries in the ELF format. Any alternate formats or |
| 39 | +special considerations for binary layout will require linker options or linker |
| 40 | +scripts. |
| 41 | + |
| 42 | +## Building the target |
| 43 | + |
| 44 | +You can build Rust with support for the target by adding it to the `target` |
| 45 | +list in `config.toml`: |
| 46 | + |
| 47 | +```toml |
| 48 | +[build] |
| 49 | +build-stage = 1 |
| 50 | +target = ["loongarch64-unknown-none"] |
| 51 | +``` |
| 52 | + |
| 53 | +## Building Rust programs |
| 54 | + |
| 55 | +```text |
| 56 | +# target flag may be used with any cargo or rustc command |
| 57 | +cargo build --target loongarch64-unknown-none |
| 58 | +``` |
| 59 | + |
| 60 | +## Testing |
| 61 | + |
| 62 | +As `loongarch64-unknown-none*` supports a variety of different environments and does |
| 63 | +not support `std`, this target does not support running the Rust test suite. |
| 64 | + |
| 65 | +## Cross-compilation toolchains and C code |
| 66 | + |
| 67 | +If you want to compile C code along with Rust (such as for Rust crates with C |
| 68 | +dependencies), you will need an appropriate `loongarch` toolchain. |
| 69 | + |
| 70 | +Rust *may* be able to use an `loongarch64-unknown-linux-gnu-` toolchain with |
| 71 | +appropriate standalone flags to build for this toolchain (depending on the assumptions |
| 72 | +of that toolchain, see below), or you may wish to use a separate |
| 73 | +`loongarch64-unknown-none` toolchain. |
| 74 | + |
| 75 | +On some `loongarch` hosts that use ELF binaries, you *may* be able to use the host |
| 76 | +C toolchain, if it does not introduce assumptions about the host environment |
| 77 | +that don't match the expectations of a standalone environment. Otherwise, you |
| 78 | +may need a separate toolchain for standalone/freestanding development, just as |
| 79 | +when cross-compiling from a non-`loongarch` platform. |
0 commit comments