Skip to content

Commit

Permalink
Add new target for supporting Neutrino QNX 7.1 with io-socket netwo…
Browse files Browse the repository at this point in the history
…rk stack
  • Loading branch information
flba-eb committed Nov 29, 2024
1 parent 5bbbc09 commit 6116b6a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 9 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,7 @@ supported_targets! {

("aarch64-unknown-nto-qnx700", aarch64_unknown_nto_qnx700),
("aarch64-unknown-nto-qnx710", aarch64_unknown_nto_qnx710),
("aarch64-unknown-nto-qnx710-iosock", aarch64_unknown_nto_qnx710_iosock),
("x86_64-pc-nto-qnx710", x86_64_pc_nto_qnx710),
("i586-pc-nto-qnx700", i586_pc_nto_qnx700),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::spec::{Cc, LinkerFlavor, Lld, Target, TargetOptions};

pub(crate) fn target() -> Target {
let mut target = super::aarch64_unknown_nto_qnx710::target();
target.options.env = "nto71_iosock".into();
target.options.pre_link_args = TargetOptions::link_args(
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
&["-Vgcc_ntoaarch64le_cxx", get_iosock_param()],
);
target
}

// When using `io-sock` on QNX, we must add a search path for the linker so
// that it prefers the io-sock version.
// The path depends on the host, i.e. we cannot hard-code it here, but have
// to determine it when the compiler runs.
// When using the QNX toolchain, the environment variable QNX_TARGET is always set.
// More information:
// https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.io_sock/topic/migrate_app.html
fn get_iosock_param() -> &'static str {
let target_dir = std::env::var("QNX_TARGET").expect("Environment variable QNX_TARGET is set");
let linker_param = format!("-L{target_dir}/aarch64le/io-sock/lib");

linker_param.leak()
}
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ test = true
level = "warn"
check-cfg = [
'cfg(bootstrap)',
'cfg(target_arch, values("xtensa"))',
'cfg(target_arch, values("xtensa", "aarch64-unknown-nto-qnx710-iosock"))',
# std use #[path] imports to portable-simd `std_float` crate
# and to the `backtrace` crate which messes-up with Cargo list
# of declared features, we therefor expect any feature cfg
Expand Down
7 changes: 4 additions & 3 deletions library/std/src/sys/pal/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{fmt, mem, sys};

cfg_if::cfg_if! {
// This workaround is only needed for QNX 7.0 and 7.1. The bug should have been fixed in 8.0
if #[cfg(any(target_env = "nto70", target_env = "nto71"))] {
if #[cfg(any(target_env = "nto70", target_env = "nto71", target_env = "nto71_iosock"))] {
use crate::thread;
use libc::{c_char, posix_spawn_file_actions_t, posix_spawnattr_t};
use crate::time::Duration;
Expand Down Expand Up @@ -191,7 +191,8 @@ impl Command {
target_os = "watchos",
target_os = "tvos",
target_env = "nto70",
target_env = "nto71"
target_env = "nto71",
target_env = "nto71_iosock",
)))]
unsafe fn do_fork(&mut self) -> Result<pid_t, io::Error> {
cvt(libc::fork())
Expand All @@ -202,7 +203,7 @@ impl Command {
// Documentation says "... or try calling fork() again". This is what we do here.
// See also https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/f/fork.html
// This workaround is only needed for QNX 7.0 and 7.1. The bug should have been fixed in 8.0
#[cfg(any(target_env = "nto70", target_env = "nto71"))]
#[cfg(any(target_env = "nto70", target_env = "nto71", target_env = "nto71_iosock"))]
unsafe fn do_fork(&mut self) -> Result<pid_t, io::Error> {
use crate::sys::os::errno;

Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Finder {
// Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap).
const STAGE0_MISSING_TARGETS: &[&str] = &[
// just a dummy comment so the list doesn't get onelined
"aarch64-unknown-nto-qnx710-iosock"
];

/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
Expand Down
3 changes: 2 additions & 1 deletion src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ target | std | host | notes
[`aarch64-nintendo-switch-freestanding`](platform-support/aarch64-nintendo-switch-freestanding.md) | * | | ARM64 Nintendo Switch, Horizon
[`aarch64-unknown-teeos`](platform-support/aarch64-unknown-teeos.md) | ? | | ARM64 TEEOS |
[`aarch64-unknown-nto-qnx700`](platform-support/nto-qnx.md) | ? | | ARM64 QNX Neutrino 7.0 RTOS |
[`aarch64-unknown-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | ARM64 QNX Neutrino 7.1 RTOS |
[`aarch64-unknown-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | ARM64 QNX Neutrino 7.1 RTOS with default network stack (io-pkt) |
[`aarch64-unknown-nto-qnx710-iosock`](platform-support/nto-qnx.md) | ✓ | | ARM64 QNX Neutrino 7.1 RTOS with new network stack (io-sock) |
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
[`aarch64-unknown-hermit`](platform-support/hermit.md) | ✓ | | ARM64 Hermit
`aarch64-unknown-illumos` | ✓ | ✓ | ARM64 illumos
Expand Down
15 changes: 12 additions & 3 deletions src/doc/rustc/src/platform-support/nto-qnx.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ Currently, the following QNX Neutrino versions and compilation targets are suppo

| QNX Neutrino Version | Target Architecture | Full support | `no_std` support |
|----------------------|---------------------|:------------:|:----------------:|
| 7.1 | AArch64 |||
| 7.1 with io-pkt | AArch64 |||
| 7.1 with io-sock | AArch64 |||
| 7.1 | x86_64 |||
| 7.0 | AArch64 | ? ||
| 7.0 | x86 | ||

On QNX 7.0 and 7.1, `io-pkt` is used as network stack by default. QNX 7.1 includes
the optional network stack `io-sock`.

Adding other architectures that are supported by QNX Neutrino is possible.

In the table above, 'full support' indicates support for building Rust applications with the full standard library.
Expand Down Expand Up @@ -107,7 +111,8 @@ There are no further known requirements.
For conditional compilation, following QNX Neutrino specific attributes are defined:

- `target_os` = `"nto"`
- `target_env` = `"nto71"` (for QNX Neutrino 7.1)
- `target_env` = `"nto71"` (for QNX Neutrino 7.1 with "classic" network stack "io_pkt")
- `target_env` = `"nto71_iosock"` (for QNX Neutrino 7.1 with network stack "io_sock")
- `target_env` = `"nto70"` (for QNX Neutrino 7.0)

## Building the target
Expand All @@ -134,14 +139,18 @@ export build_env='
CFLAGS_aarch64-unknown-nto-qnx710=-Vgcc_ntoaarch64le_cxx
CXX_aarch64-unknown-nto-qnx710=qcc
AR_aarch64_unknown_nto_qnx710=ntoaarch64-ar
CC_aarch64-unknown-nto-qnx710-iosock=qcc
CFLAGS_aarch64-unknown-nto-qnx710-iosock=-Vgcc_ntoaarch64le_cxx
CXX_aarch64-unknown-nto-qnx710-iosock=qcc
AR_aarch64_unknown_nto_qnx710_iosock=ntoaarch64-ar
CC_x86_64-pc-nto-qnx710=qcc
CFLAGS_x86_64-pc-nto-qnx710=-Vgcc_ntox86_64_cxx
CXX_x86_64-pc-nto-qnx710=qcc
AR_x86_64_pc_nto_qnx710=ntox86_64-ar'

env $build_env \
./x.py build \
--target aarch64-unknown-nto-qnx710,x86_64-pc-nto-qnx710,x86_64-unknown-linux-gnu \
--target aarch64-unknown-nto-qnx710-iosock,aarch64-unknown-nto-qnx710,x86_64-pc-nto-qnx710,x86_64-unknown-linux-gnu \
rustc library/core library/alloc library/std
```

Expand Down
3 changes: 3 additions & 0 deletions tests/assembly/targets/targets-elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
//@ revisions: aarch64_unknown_nto_qnx710
//@ [aarch64_unknown_nto_qnx710] compile-flags: --target aarch64-unknown-nto-qnx710
//@ [aarch64_unknown_nto_qnx710] needs-llvm-components: aarch64
//@ revisions: aarch64_unknown_nto_qnx710_iosock
//@ [aarch64_unknown_nto_qnx710] compile-flags: --target aarch64-unknown-nto-qnx710-iosock
//@ [aarch64_unknown_nto_qnx710] needs-llvm-components: aarch64
//@ revisions: aarch64_unknown_openbsd
//@ [aarch64_unknown_openbsd] compile-flags: --target aarch64-unknown-openbsd
//@ [aarch64_unknown_openbsd] needs-llvm-components: aarch64
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/check-cfg/well-known-values.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
LL | target_env = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_env` are: ``, `gnu`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p1`, `p2`, `relibc`, `sgx`, and `uclibc`
= note: expected values for `target_env` are: ``, `gnu`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `nto71_iosock`, `ohos`, `p1`, `p2`, `relibc`, `sgx`, and `uclibc`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration

warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
Expand Down

0 comments on commit 6116b6a

Please sign in to comment.