Skip to content
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

Support QNX 7.1 with io-sock+libstd and QNX 8.0 (no_std only) #133631

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 94 additions & 1 deletion compiler/rustc_target/src/spec/base/nto_qnx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::spec::{RelroLevel, TargetOptions, cvs};
use crate::spec::{
Cc, LinkArgs, LinkerFlavor, Lld, RelroLevel, Target, TargetMetadata, TargetOptions, cvs,
};

pub(crate) fn opts() -> TargetOptions {
TargetOptions {
Expand All @@ -16,3 +18,94 @@ pub(crate) fn opts() -> TargetOptions {
..Default::default()
}
}

pub(crate) fn meta() -> TargetMetadata {
TargetMetadata { description: None, tier: Some(3), host_tools: Some(false), std: Some(true) }
}

pub(crate) fn aarch64() -> Target {
Target {
llvm_target: "aarch64-unknown-unknown".into(),
metadata: meta(),
pointer_width: 64,
// from: https://llvm.org/docs/LangRef.html#data-layout
// e = little endian
// m:e = ELF mangling: Private symbols get a .L prefix
// i8:8:32 = 8-bit-integer, minimum_alignment=8, preferred_alignment=32
// i16:16:32 = 16-bit-integer, minimum_alignment=16, preferred_alignment=32
// i64:64 = 64-bit-integer, minimum_alignment=64, preferred_alignment=64
// i128:128 = 128-bit-integer, minimum_alignment=128, preferred_alignment=128
// n32:64 = 32 and 64 are native integer widths; Elements of this set are considered to support most general arithmetic operations efficiently.
// S128 = 128 bits are the natural alignment of the stack in bits.
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
arch: "aarch64".into(),
options: TargetOptions {
features: "+v8a".into(),
max_atomic_width: Some(128),
..opts()
}
}
}

pub(crate) fn x86_64() -> Target {
Target {
llvm_target: "x86_64-pc-unknown".into(),
metadata: meta(),
pointer_width: 64,
data_layout:
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
arch: "x86_64".into(),
options: TargetOptions {
cpu: "x86-64".into(),
plt_by_default: false,
max_atomic_width: Some(64),
vendor: "pc".into(),
..opts()
},
}
}

pub(crate) fn pre_link_args(api_var: ApiVariant, arch: Arch) -> LinkArgs {
let (qcc_arg, arch_lib_dir) = match arch {
Arch::Aarch64 => ("-Vgcc_ntoaarch64le_cxx", "aarch64le"),
Arch::I586 => {
("-Vgcc_ntox86_cxx", "notSupportedByQnx_compiler/rustc_target/src/spec/base/nto_qnx.rs")
}
Arch::X86_64 => ("-Vgcc_ntox86_64_cxx", "x86_64"),
};
match api_var {
ApiVariant::Default => {
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[qcc_arg])
}
ApiVariant::IoSock => TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[
qcc_arg,
get_iosock_param(arch_lib_dir),
]),
}
}

pub(crate) enum ApiVariant {
Default,
IoSock,
}

pub(crate) enum Arch {
Aarch64,
I586,
X86_64,
}

// 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(arch_lib_dir: &str) -> &'static str {
let target_dir = std::env::var("QNX_TARGET")
.unwrap_or_else(|_| "QNX_TARGET_not_set_please_source_qnxsdp-env.sh".into());
let linker_param = format!("-L{target_dir}/{arch_lib_dir}/io-sock/lib");

linker_param.leak()
}
4 changes: 4 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,11 @@ 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),
("aarch64-unknown-nto-qnx800", aarch64_unknown_nto_qnx800),
("x86_64-pc-nto-qnx710", x86_64_pc_nto_qnx710),
("x86_64-pc-nto-qnx710_iosock", x86_64_pc_nto_qnx710_iosock),
("x86_64-pc-nto-qnx800", x86_64_pc_nto_qnx800),
("i586-pc-nto-qnx700", i586_pc_nto_qnx700),

("aarch64-unknown-linux-ohos", aarch64_unknown_linux_ohos),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
use crate::spec::{Cc, LinkerFlavor, Lld, Target, TargetOptions, base};
use crate::spec::Target;
use crate::spec::base::nto_qnx;

pub(crate) fn target() -> Target {
// In QNX, libc does not provide a compatible ABI between versions.
// To distinguish between QNX versions, we needed a stable conditional compilation switch,
// which is why we needed to implement different targets in the compiler.
Target {
llvm_target: "aarch64-unknown-unknown".into(),
metadata: crate::spec::TargetMetadata {
description: Some("ARM64 QNX Neutrino 7.0 RTOS".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(true),
},
pointer_width: 64,
// from: https://llvm.org/docs/LangRef.html#data-layout
// e = little endian
// m:e = ELF mangling: Private symbols get a .L prefix
// i8:8:32 = 8-bit-integer, minimum_alignment=8, preferred_alignment=32
// i16:16:32 = 16-bit-integer, minimum_alignment=16, preferred_alignment=32
// i64:64 = 64-bit-integer, minimum_alignment=64, preferred_alignment=64
// i128:128 = 128-bit-integer, minimum_alignment=128, preferred_alignment=128
// n32:64 = 32 and 64 are native integer widths; Elements of this set are considered to support most general arithmetic operations efficiently.
// S128 = 128 bits are the natural alignment of the stack in bits.
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
arch: "aarch64".into(),
options: TargetOptions {
features: "+v8a".into(),
max_atomic_width: Some(128),
pre_link_args: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[
"-Vgcc_ntoaarch64le_cxx",
]),
env: "nto70".into(),
..base::nto_qnx::opts()
},
}
let mut target = nto_qnx::aarch64();
target.metadata.description = Some("ARM64 QNX Neutrino 7.0 RTOS".into());
target.options.pre_link_args =
nto_qnx::pre_link_args(nto_qnx::ApiVariant::Default, nto_qnx::Arch::Aarch64);
target.options.env = "nto70".into();
target
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use crate::spec::Target;
use crate::spec::base::nto_qnx;

pub(crate) fn target() -> Target {
let mut base = super::aarch64_unknown_nto_qnx700::target();
base.metadata.description = Some("ARM64 QNX Neutrino 7.1 RTOS".into());
base.options.env = "nto71".into();
base
let mut target = nto_qnx::aarch64();
target.metadata.description =
Some("ARM64 QNX Neutrino 7.1 RTOS with io-pkt network stack".into());
target.options.pre_link_args =
nto_qnx::pre_link_args(nto_qnx::ApiVariant::Default, nto_qnx::Arch::Aarch64);
target.options.env = "nto71".into();
target
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::spec::Target;
use crate::spec::base::nto_qnx;

pub(crate) fn target() -> Target {
let mut target = nto_qnx::aarch64();
target.metadata.description =
Some("ARM64 QNX Neutrino 7.1 RTOS with io-sock network stack".into());
target.options.pre_link_args =
nto_qnx::pre_link_args(nto_qnx::ApiVariant::IoSock, nto_qnx::Arch::Aarch64);
target.options.env = "nto71_iosock".into();
target
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::spec::Target;
use crate::spec::base::nto_qnx;

pub(crate) fn target() -> Target {
let mut target = nto_qnx::aarch64();
target.metadata.description = Some("ARM64 QNX Neutrino 8.0 RTOS".into());
target.options.pre_link_args =
nto_qnx::pre_link_args(nto_qnx::ApiVariant::Default, nto_qnx::Arch::Aarch64);
target.options.env = "nto80".into();
target
}
20 changes: 10 additions & 10 deletions compiler/rustc_target/src/spec/targets/i586_pc_nto_qnx700.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions, base};
use crate::spec::base::nto_qnx;
use crate::spec::{StackProbeType, Target, TargetOptions, base};

pub(crate) fn target() -> Target {
let mut meta = nto_qnx::meta();
meta.description = Some("32-bit x86 QNX Neutrino 7.0 RTOS".into());
meta.std = Some(false);
Target {
llvm_target: "i586-pc-unknown".into(),
metadata: crate::spec::TargetMetadata {
description: Some("32-bit x86 QNX Neutrino 7.0 RTOS".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(false),
},
metadata: meta,
pointer_width: 32,
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
i128:128-f64:32:64-f80:32-n8:16:32-S128"
Expand All @@ -17,9 +16,10 @@ pub(crate) fn target() -> Target {
options: TargetOptions {
cpu: "pentium4".into(),
max_atomic_width: Some(64),
pre_link_args: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[
"-Vgcc_ntox86_cxx",
]),
pre_link_args: nto_qnx::pre_link_args(
nto_qnx::ApiVariant::Default,
nto_qnx::Arch::I586,
),
env: "nto70".into(),
vendor: "pc".into(),
stack_probes: StackProbeType::Inline,
Expand Down
34 changes: 9 additions & 25 deletions compiler/rustc_target/src/spec/targets/x86_64_pc_nto_qnx710.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
use crate::spec::{Cc, LinkerFlavor, Lld, Target, TargetOptions, base};
use crate::spec::Target;
use crate::spec::base::nto_qnx;

pub(crate) fn target() -> Target {
Target {
llvm_target: "x86_64-pc-unknown".into(),
metadata: crate::spec::TargetMetadata {
description: Some("x86 64-bit QNX Neutrino 7.1 RTOS".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(true),
},
pointer_width: 64,
data_layout:
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
arch: "x86_64".into(),
options: TargetOptions {
cpu: "x86-64".into(),
plt_by_default: false,
max_atomic_width: Some(64),
pre_link_args: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[
"-Vgcc_ntox86_64_cxx",
]),
env: "nto71".into(),
vendor: "pc".into(),
..base::nto_qnx::opts()
},
}
let mut target = nto_qnx::x86_64();
target.metadata.description =
Some("x86 64-bit QNX Neutrino 7.1 RTOS with io-pkt network stack".into());
target.options.pre_link_args =
nto_qnx::pre_link_args(nto_qnx::ApiVariant::Default, nto_qnx::Arch::X86_64);
target.options.env = "nto71".into();
target
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::spec::Target;
use crate::spec::base::nto_qnx;

pub(crate) fn target() -> Target {
let mut target = nto_qnx::x86_64();
target.metadata.description =
Some("x86 64-bit QNX Neutrino 7.1 RTOS with io-sock network stack".into());
target.options.pre_link_args =
nto_qnx::pre_link_args(nto_qnx::ApiVariant::IoSock, nto_qnx::Arch::X86_64);
target.options.env = "nto71_iosock".into();
target
}
11 changes: 11 additions & 0 deletions compiler/rustc_target/src/spec/targets/x86_64_pc_nto_qnx800.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::spec::Target;
use crate::spec::base::nto_qnx;

pub(crate) fn target() -> Target {
let mut target = nto_qnx::x86_64();
target.metadata.description = Some("x86 64-bit QNX Neutrino 8.0 RTOS".into());
target.options.pre_link_args =
nto_qnx::pre_link_args(nto_qnx::ApiVariant::Default, nto_qnx::Arch::X86_64);
target.options.env = "nto80".into();
target
}
3 changes: 2 additions & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ test = true
level = "warn"
check-cfg = [
'cfg(bootstrap)',
'cfg(target_arch, values("xtensa"))',
'cfg(target_arch, values("xtensa", "aarch64-unknown-nto-qnx710_iosock", "x86_64-pc-nto-qnx710_iosock", "x86_64-pc-nto-qnx800","aarch64-unknown-nto-qnx800"))',
'cfg(target_env, values("nto71_iosock", "nto80"))',
# 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
13 changes: 3 additions & 10 deletions library/std/src/sys/pal/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use crate::sys::process::process_common::*;
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(target_os = "nto")] {
use crate::thread;
use libc::{c_char, posix_spawn_file_actions_t, posix_spawnattr_t};
use crate::time::Duration;
Expand Down Expand Up @@ -187,12 +186,7 @@ impl Command {

// Attempts to fork the process. If successful, returns Ok((0, -1))
// in the child, and Ok((child_pid, -1)) in the parent.
#[cfg(not(any(
target_os = "watchos",
target_os = "tvos",
target_env = "nto70",
target_env = "nto71"
)))]
#[cfg(not(any(target_os = "watchos", target_os = "tvos", target_os = "nto")))]
unsafe fn do_fork(&mut self) -> Result<pid_t, io::Error> {
cvt(libc::fork())
}
Expand All @@ -201,8 +195,7 @@ impl Command {
// or closed a file descriptor while the fork() was occurring".
// 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(target_os = "nto")]
unsafe fn do_fork(&mut self) -> Result<pid_t, io::Error> {
use crate::sys::os::errno;

Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ 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",
"x86_64-pc-nto-qnx710_iosock",
"x86_64-pc-nto-qnx800",
"aarch64-unknown-nto-qnx800",
];

/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
Expand Down
8 changes: 6 additions & 2 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ 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-nto-qnx800`](platform-support/nto-qnx.md) | ✓ | | ARM64 QNX Neutrino 8.0 RTOS |
[`aarch64-unknown-freebsd`](platform-support/freebsd.md) | ✓ | ✓ | ARM64 FreeBSD
[`aarch64-unknown-hermit`](platform-support/hermit.md) | ✓ | | ARM64 Hermit
`aarch64-unknown-illumos` | ✓ | ✓ | ARM64 illumos
Expand Down Expand Up @@ -380,7 +382,9 @@ target | std | host | notes
[`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly
[`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ✓ | | x86 64-bit tvOS
[`x86_64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | x86 64-bit Apple WatchOS simulator
[`x86_64-pc-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 7.1 RTOS |
[`x86_64-pc-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 7.1 RTOS with default network stack (io-pkt) |
[`x86_64-pc-nto-qnx710_iosock`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 7.1 RTOS with new network stack (io-sock) |
[`x86_64-pc-nto-qnx800`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 8.0 RTOS |
[`x86_64-unikraft-linux-musl`](platform-support/unikraft-linux-musl.md) | ✓ | | 64-bit Unikraft with musl 1.2.3
`x86_64-unknown-dragonfly` | ✓ | ✓ | 64-bit DragonFlyBSD
`x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku
Expand Down
Loading
Loading