Skip to content

Commit fc7c3ca

Browse files
committed
Add X86 target support for NuttX
* Implement `i686-unknown-nuttx` and `x86_64-unknown-nuttx` target definitions * Integrate new targets into the platform support documentation * Update tests to include new target revisions This change introduces support for 32-bit and 64-bit x86 architectures on the NuttX operating system, enhancing the range of platforms Rust can target. The targets are defined as tier 3, indicating that they are supported but not automatically tested by the Rust project. The `i686-unknown-nuttx` target uses the `pentium4` CPU and 32-bit pointers, while the `x86_64-unknown-nuttx` target uses the `x86-64` CPU and 64-bit pointers. Both targets disable dynamic linking and use inline stack probes for improved performance and reliability in a bare-metal environment. Additionally, this commit updates the platform support documentation to list the new targets and includes them in the test suite to ensure that they build correctly. Signed-off-by: Huang Qi <[email protected]>
1 parent e5f11af commit fc7c3ca

File tree

6 files changed

+90
-0
lines changed

6 files changed

+90
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,8 @@ supported_targets! {
20042004

20052005
("x86_64-unknown-linux-none", x86_64_unknown_linux_none),
20062006

2007+
("i686-unknown-nuttx", i686_unknown_nuttx),
2008+
("x86_64-unknown-nuttx", x86_64_unknown_nuttx),
20072009
("thumbv6m-nuttx-eabi", thumbv6m_nuttx_eabi),
20082010
("thumbv7a-nuttx-eabi", thumbv7a_nuttx_eabi),
20092011
("thumbv7a-nuttx-eabihf", thumbv7a_nuttx_eabihf),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, RelocModel, StackProbeType, Target, TargetOptions, cvs};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = TargetOptions {
5+
os: "nuttx".into(),
6+
dynamic_linking: false,
7+
families: cvs!["unix"],
8+
no_default_libraries: true,
9+
has_rpath: false,
10+
position_independent_executables: false,
11+
relocation_model: RelocModel::Static,
12+
relro_level: crate::spec::RelroLevel::Full,
13+
has_thread_local: true,
14+
use_ctors_section: true,
15+
..Default::default()
16+
};
17+
base.cpu = "pentium4".into();
18+
base.max_atomic_width = Some(64);
19+
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
20+
base.stack_probes = StackProbeType::Inline;
21+
22+
Target {
23+
llvm_target: "i686-unknown-nuttx".into(),
24+
metadata: crate::spec::TargetMetadata {
25+
description: Some("NuttX/x86".into()),
26+
tier: Some(3),
27+
host_tools: Some(false),
28+
std: Some(true),
29+
},
30+
pointer_width: 32,
31+
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
32+
i128:128-f64:32:64-f80:32-n8:16:32-S128"
33+
.into(),
34+
arch: "x86".into(),
35+
options: base,
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Generic x86-64 target for NuttX RTOS
2+
//
3+
// Can be used in conjunction with the `target-feature` and
4+
// `target-cpu` compiler flags to opt-in more hardware-specific
5+
// features.
6+
7+
use crate::spec::{RelocModel, StackProbeType, Target, TargetOptions, cvs};
8+
9+
pub(crate) fn target() -> Target {
10+
let mut base = TargetOptions {
11+
os: "nuttx".into(),
12+
dynamic_linking: false,
13+
families: cvs!["unix"],
14+
no_default_libraries: true,
15+
has_rpath: false,
16+
position_independent_executables: false,
17+
relocation_model: RelocModel::Static,
18+
relro_level: crate::spec::RelroLevel::Full,
19+
has_thread_local: true,
20+
use_ctors_section: true,
21+
..Default::default()
22+
};
23+
base.cpu = "x86-64".into();
24+
base.max_atomic_width = Some(64);
25+
base.stack_probes = StackProbeType::Inline;
26+
27+
Target {
28+
llvm_target: "x86_64-unknown-nuttx".into(),
29+
metadata: crate::spec::TargetMetadata {
30+
description: Some("NuttX/x86_64".into()),
31+
tier: Some(3),
32+
host_tools: Some(false),
33+
std: Some(true),
34+
},
35+
pointer_width: 64,
36+
data_layout:
37+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
38+
arch: "x86_64".into(),
39+
options: base,
40+
}
41+
}

src/doc/rustc/src/platform-support.md

+2
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ target | std | host | notes
314314
`i686-unknown-haiku` | ✓ | ✓ | 32-bit Haiku (Pentium 4) [^x86_32-floats-return-ABI]
315315
[`i686-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 32-bit GNU/Hurd (PentiumPro) [^x86_32-floats-x87]
316316
[`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 (Pentium 4) [^x86_32-floats-return-ABI]
317+
[`i686-unknown-nuttx`](platform-support/nuttx.md) | ✓ | | 32-bit x86 with NuttX
317318
[`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD (Pentium 4) [^x86_32-floats-return-ABI]
318319
[`i686-unknown-redox`](platform-support/redox.md) | ✓ | | i686 Redox OS (PentiumPro) [^x86_32-floats-x87]
319320
`i686-uwp-windows-gnu` | ✓ | | [^x86_32-floats-return-ABI]
@@ -417,6 +418,7 @@ target | std | host | notes
417418
`x86_64-unknown-l4re-uclibc` | ? | |
418419
[`x86_64-unknown-linux-none`](platform-support/x86_64-unknown-linux-none.md) | * | | 64-bit Linux with no libc
419420
[`x86_64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 64-bit OpenBSD
421+
[`x86_64-unknown-nuttx`](platform-support/nuttx.md) | ✓ | | 64-bit x86 with NuttX
420422
[`x86_64-unknown-trusty`](platform-support/trusty.md) | ? | |
421423
`x86_64-uwp-windows-gnu` | ✓ | |
422424
[`x86_64-uwp-windows-msvc`](platform-support/uwp-windows-msvc.md) | ✓ | |

src/doc/rustc/src/platform-support/nuttx.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The target name follow this format: `ARCH[-VENDOR]-nuttx-ABI`, where `ARCH` is t
2020

2121
The following target names are defined:
2222

23+
- `i686-unknown-nuttx`
24+
- `x86_64-unknown-nuttx`
2325
- `aarch64-unknown-nuttx`
2426
- `armv7a-nuttx-eabi`
2527
- `armv7a-nuttx-eabihf`

tests/assembly/targets/targets-elf.rs

+6
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@
249249
//@ revisions: i686_unknown_netbsd
250250
//@ [i686_unknown_netbsd] compile-flags: --target i686-unknown-netbsd
251251
//@ [i686_unknown_netbsd] needs-llvm-components: x86
252+
//@ revisions: i686_unknown_nuttx
253+
//@ [i686_unknown_nuttx] compile-flags: --target i686-unknown-nuttx
254+
//@ [i686_unknown_nuttx] needs-llvm-components: x86
252255
//@ revisions: i686_unknown_openbsd
253256
//@ [i686_unknown_openbsd] compile-flags: --target i686-unknown-openbsd
254257
//@ [i686_unknown_openbsd] needs-llvm-components: x86
@@ -627,6 +630,9 @@
627630
//@ revisions: x86_64_unknown_none
628631
//@ [x86_64_unknown_none] compile-flags: --target x86_64-unknown-none
629632
//@ [x86_64_unknown_none] needs-llvm-components: x86
633+
//@ revisions: x86_64_unknown_nuttx
634+
//@ [x86_64_unknown_nuttx] compile-flags: --target x86_64-unknown-nuttx
635+
//@ [x86_64_unknown_nuttx] needs-llvm-components: x86
630636
//@ revisions: x86_64_unknown_openbsd
631637
//@ [x86_64_unknown_openbsd] compile-flags: --target x86_64-unknown-openbsd
632638
//@ [x86_64_unknown_openbsd] needs-llvm-components: x86

0 commit comments

Comments
 (0)