From 5a0ce36232101334da178f154ec79066cb5f2a61 Mon Sep 17 00:00:00 2001 From: YunQiang Su Date: Fri, 3 Jan 2025 09:16:05 +0800 Subject: [PATCH 1/3] Target: Add mips mti baremetal support Do the same thing as gcc, which use the vendor `mti` to mark the toolchain as MIPS32r2 default. We support both big endian and little endian flavor: mips-mti-none-elf mipsel-mti-none-elf --- compiler/rustc_target/src/spec/mod.rs | 2 ++ .../src/spec/targets/mips_mti_none_elf.rs | 36 +++++++++++++++++++ .../src/spec/targets/mipsel_mti_none_elf.rs | 36 +++++++++++++++++++ src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 2 ++ .../src/platform-support/mips-mti-none-elf.md | 31 ++++++++++++++++ src/tools/build-manifest/src/main.rs | 2 ++ tests/assembly/targets/targets-elf.rs | 6 ++++ tests/ui/check-cfg/well-known-values.stderr | 2 +- 9 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 compiler/rustc_target/src/spec/targets/mips_mti_none_elf.rs create mode 100644 compiler/rustc_target/src/spec/targets/mipsel_mti_none_elf.rs create mode 100644 src/doc/rustc/src/platform-support/mips-mti-none-elf.md diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 02962d55a60ed..bfe6f44414717 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1926,6 +1926,8 @@ supported_targets! { ("mipsel-sony-psp", mipsel_sony_psp), ("mipsel-sony-psx", mipsel_sony_psx), ("mipsel-unknown-none", mipsel_unknown_none), + ("mips-mti-none-elf", mips_mti_none_elf), + ("mipsel-mti-none-elf", mipsel_mti_none_elf), ("thumbv4t-none-eabi", thumbv4t_none_eabi), ("armv4t-none-eabi", armv4t_none_eabi), ("thumbv5te-none-eabi", thumbv5te_none_eabi), diff --git a/compiler/rustc_target/src/spec/targets/mips_mti_none_elf.rs b/compiler/rustc_target/src/spec/targets/mips_mti_none_elf.rs new file mode 100644 index 0000000000000..4637e31fb1745 --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/mips_mti_none_elf.rs @@ -0,0 +1,36 @@ +use crate::abi::Endian; +use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions}; + +pub(crate) fn target() -> Target { + Target { + data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + llvm_target: "mips".into(), + metadata: crate::spec::TargetMetadata { + description: Some("MIPS32r2 BE Baremetal Softfloat".into()), + tier: Some(3), + host_tools: Some(false), + std: None, // ? + }, + pointer_width: 32, + arch: "mips".into(), + + options: TargetOptions { + vendor: "mti".into(), + linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), + linker: Some("rust-lld".into()), + endian: Endian::Big, + cpu: "mips32r2".into(), + + max_atomic_width: Some(32), + + features: "+mips32r2,+soft-float,+noabicalls".into(), + executables: true, + panic_strategy: PanicStrategy::Abort, + relocation_model: RelocModel::Static, + emit_debug_gdb_scripts: false, + eh_frame_header: false, + singlethread: true, + ..Default::default() + }, + } +} diff --git a/compiler/rustc_target/src/spec/targets/mipsel_mti_none_elf.rs b/compiler/rustc_target/src/spec/targets/mipsel_mti_none_elf.rs new file mode 100644 index 0000000000000..a89c0fce88c6a --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/mipsel_mti_none_elf.rs @@ -0,0 +1,36 @@ +use crate::abi::Endian; +use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions}; + +pub(crate) fn target() -> Target { + Target { + data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + llvm_target: "mipsel".into(), + metadata: crate::spec::TargetMetadata { + description: Some("MIPS32r2 LE Baremetal Softfloat".into()), + tier: Some(3), + host_tools: Some(false), + std: None, // ? + }, + pointer_width: 32, + arch: "mips".into(), + + options: TargetOptions { + vendor: "mti".into(), + linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), + linker: Some("rust-lld".into()), + endian: Endian::Little, + cpu: "mips32r2".into(), + + max_atomic_width: Some(32), + + features: "+mips32r2,+soft-float,+noabicalls".into(), + executables: true, + panic_strategy: PanicStrategy::Abort, + relocation_model: RelocModel::Static, + emit_debug_gdb_scripts: false, + eh_frame_header: false, + singlethread: true, + ..Default::default() + }, + } +} diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index f0c3720eae14f..16ae83126af0e 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -62,6 +62,7 @@ - [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md) - [mips64-openwrt-linux-musl](platform-support/mips64-openwrt-linux-musl.md) - [mipsel-sony-psx](platform-support/mipsel-sony-psx.md) + - [mips\*-mti-none-elf](platform-support/mips-mti-none-elf.md) - [mipsisa\*r6\*-unknown-linux-gnu\*](platform-support/mips-release-6.md) - [nvptx64-nvidia-cuda](platform-support/nvptx64-nvidia-cuda.md) - [powerpc-unknown-openbsd](platform-support/powerpc-unknown-openbsd.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 24e9a3c812106..5c787f56ed264 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -332,6 +332,8 @@ target | std | host | notes `mipsel-unknown-linux-uclibc` | ✓ | | MIPS (LE) Linux with uClibc [`mipsel-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | 32-bit MIPS (LE), requires mips32 cpu support `mipsel-unknown-none` | * | | Bare MIPS (LE) softfloat +[`mips-mti-none-elf`](platform-support/mips-mti-none-elf.md) | * | | Bare MIPS32r2 (BE) softfloat +[`mipsel-mti-none-elf`](platform-support/mips-mti-none-elf.md) | * | | Bare MIPS32r2 (LE) softfloat [`mipsisa32r6-unknown-linux-gnu`](platform-support/mips-release-6.md) | ? | | 32-bit MIPS Release 6 Big Endian [`mipsisa32r6el-unknown-linux-gnu`](platform-support/mips-release-6.md) | ? | | 32-bit MIPS Release 6 Little Endian [`mipsisa64r6-unknown-linux-gnuabi64`](platform-support/mips-release-6.md) | ? | | 64-bit MIPS Release 6 Big Endian diff --git a/src/doc/rustc/src/platform-support/mips-mti-none-elf.md b/src/doc/rustc/src/platform-support/mips-mti-none-elf.md new file mode 100644 index 0000000000000..b472f2f0d670c --- /dev/null +++ b/src/doc/rustc/src/platform-support/mips-mti-none-elf.md @@ -0,0 +1,31 @@ +# `mips*-mti-none-elf` + +**Tier: 3** + +MIPS32r2 baremetal softfloat, Big Endian or Little Enedian. + +- mips-mti-none-elf +- mipsel-mti-none-elf + +## Target maintainers + +- YunQiang Su, `syq@debian.org`, https://github.com/wzssyqa + +## Background + +These 2 targets, aka mips-mti-none-elf and mipsel-mti-none-elf, are for +baremetal development of MIPS32r2. The lld is used instead of Gnu-ld. + +## Requirements + +The target only supports cross compilation and no host tools. The target +supports `alloc` with a default allocator while only support `no-std` development. + +The vendor name `mti` follows the naming of gcc to indicate MIPS32r2. + +## Cross-compilation toolchains and C code + +Compatible C code can be built for this target on any compiler that has a MIPS32r2 +target. On clang and ld.lld linker, it can be generated using the +`-march=mips`/`-march=mipsel`, `-mabi=32` with llvm features flag +`features=+mips32r2,+soft-float,+noabicalls`. diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 561b611148a20..d6ca03f764304 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -128,6 +128,8 @@ static TARGETS: &[&str] = &[ "mipsisa64r6el-unknown-linux-gnuabi64", "mipsel-unknown-linux-gnu", "mipsel-unknown-linux-musl", + "mips-mti-none-elf", + "mipsel-mti-none-elf", "nvptx64-nvidia-cuda", "powerpc-unknown-linux-gnu", "powerpc64-unknown-linux-gnu", diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs index 7d50647bed18e..93394277f2499 100644 --- a/tests/assembly/targets/targets-elf.rs +++ b/tests/assembly/targets/targets-elf.rs @@ -285,6 +285,12 @@ //@ revisions: mips_unknown_linux_uclibc //@ [mips_unknown_linux_uclibc] compile-flags: --target mips-unknown-linux-uclibc //@ [mips_unknown_linux_uclibc] needs-llvm-components: mips +//@ revisions: mips_mti_none_elf +//@ [mips_mti_none_elf] compile-flags: --target mips-mti-none-elf +//@ [mips_mti_none_elf] needs-llvm-components: mips +//@ revisions: mipsel_mti_none_elf +//@ [mipsel_mti_none_elf] compile-flags: --target mipsel-mti-none-elf +//@ [mipsel_mti_none_elf] needs-llvm-components: mips //@ revisions: mipsel_sony_psp //@ [mipsel_sony_psp] compile-flags: --target mipsel-sony-psp //@ [mipsel_sony_psp] needs-llvm-components: mips diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index ab69938f51ae6..5c1898a0ae365 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -230,7 +230,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_vendor = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, and `wrs` + = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `mti`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, and `wrs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` From 51dc35017859f640663799b7989277fefae75d95 Mon Sep 17 00:00:00 2001 From: YunQiang Su Date: Sun, 5 Jan 2025 13:00:26 +0800 Subject: [PATCH 2/3] fix tests --- tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr | 2 +- tests/ui/check-cfg/exhaustive-names-values.feature.stderr | 2 +- tests/ui/check-cfg/exhaustive-names-values.full.stderr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr b/tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr index d49ed3e755182..23b6edacce77c 100644 --- a/tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr +++ b/tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr @@ -15,7 +15,7 @@ warning: unexpected `cfg` condition value: `value` LL | #[cfg(target_vendor = "value")] | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, and `wrs` + = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `mti`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, and `wrs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `feature` diff --git a/tests/ui/check-cfg/exhaustive-names-values.feature.stderr b/tests/ui/check-cfg/exhaustive-names-values.feature.stderr index 81dbbca4f8630..804d7fb9163d7 100644 --- a/tests/ui/check-cfg/exhaustive-names-values.feature.stderr +++ b/tests/ui/check-cfg/exhaustive-names-values.feature.stderr @@ -15,7 +15,7 @@ warning: unexpected `cfg` condition value: `value` LL | #[cfg(target_vendor = "value")] | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, and `wrs` + = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `mti`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, and `wrs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `unk` diff --git a/tests/ui/check-cfg/exhaustive-names-values.full.stderr b/tests/ui/check-cfg/exhaustive-names-values.full.stderr index 81dbbca4f8630..804d7fb9163d7 100644 --- a/tests/ui/check-cfg/exhaustive-names-values.full.stderr +++ b/tests/ui/check-cfg/exhaustive-names-values.full.stderr @@ -15,7 +15,7 @@ warning: unexpected `cfg` condition value: `value` LL | #[cfg(target_vendor = "value")] | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, and `wrs` + = note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `mti`, `nintendo`, `nvidia`, `pc`, `risc0`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, and `wrs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `unk` From 1a8228707040a0bd718991fbbeda8a428fbb8938 Mon Sep 17 00:00:00 2001 From: YunQiang Su Date: Sun, 5 Jan 2025 14:46:54 +0800 Subject: [PATCH 3/3] Update src/doc/rustc/src/platform-support/mips-mti-none-elf.md Co-authored-by: Oli Scherer --- src/doc/rustc/src/platform-support/mips-mti-none-elf.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support/mips-mti-none-elf.md b/src/doc/rustc/src/platform-support/mips-mti-none-elf.md index b472f2f0d670c..731f0a8c42f18 100644 --- a/src/doc/rustc/src/platform-support/mips-mti-none-elf.md +++ b/src/doc/rustc/src/platform-support/mips-mti-none-elf.md @@ -2,7 +2,7 @@ **Tier: 3** -MIPS32r2 baremetal softfloat, Big Endian or Little Enedian. +MIPS32r2 baremetal softfloat, Big Endian or Little Endian. - mips-mti-none-elf - mipsel-mti-none-elf