-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add tier 3 no_std AArch64/x86_64 support for the QNX Neutrino RTOS #102701
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
compiler/rustc_target/src/spec/aarch64_unknown_nto_qnx_710.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use super::nto_qnx_base; | ||
use crate::spec::{Cc, LinkerFlavor, Lld, Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
Target { | ||
llvm_target: "aarch64-unknown-unknown".into(), | ||
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-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), | ||
arch: "aarch64".into(), | ||
options: TargetOptions { | ||
max_atomic_width: Some(128), | ||
pre_link_args: TargetOptions::link_args( | ||
LinkerFlavor::Gnu(Cc::Yes, Lld::No), | ||
&["-Vgcc_ntoaarch64le_cxx"], | ||
), | ||
..nto_qnx_base::opts() | ||
}, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::spec::{cvs, RelroLevel, TargetOptions}; | ||
|
||
pub fn opts() -> TargetOptions { | ||
TargetOptions { | ||
crt_static_respected: true, | ||
dynamic_linking: true, | ||
env: "nto71".into(), | ||
executables: true, | ||
families: cvs!["unix"], | ||
has_rpath: true, | ||
has_thread_local: false, | ||
flba-eb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
linker: Some("qcc".into()), | ||
os: "nto".into(), | ||
position_independent_executables: true, | ||
static_position_independent_executables: true, | ||
relro_level: RelroLevel::Full, | ||
..Default::default() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use super::nto_qnx_base; | ||
use crate::spec::{Cc, LinkerFlavor, Lld, Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
Target { | ||
llvm_target: "x86_64-pc-unknown".into(), | ||
pointer_width: 64, | ||
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
.into(), | ||
arch: "x86_64".into(), | ||
options: TargetOptions { | ||
cpu: "x86-64".into(), | ||
max_atomic_width: Some(64), | ||
pre_link_args: TargetOptions::link_args( | ||
LinkerFlavor::Gnu(Cc::Yes, Lld::No), | ||
&["-Vgcc_ntox86_64_cxx"], | ||
), | ||
..nto_qnx_base::opts() | ||
}, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# nto-qnx | ||
|
||
**Tier: 3** | ||
|
||
[BlackBerry® QNX®][BlackBerry] Neutrino (nto) Real-time operating system. | ||
The support has been implemented jointly by [Elektrobit Automotive GmbH][Elektrobit] | ||
and [BlackBerry][BlackBerry]. | ||
|
||
[BlackBerry]: https://blackberry.qnx.com | ||
[Elektrobit]: https://www.elektrobit.com | ||
|
||
## Target maintainers | ||
|
||
- Florian Bartels, `[email protected]`, https://github.com/flba-eb | ||
- Tristan Roach, `[email protected]`, https://github.com/gh-tr | ||
|
||
## Requirements | ||
|
||
Currently, only cross-compilation for QNX Neutrino on AArch64 and x86_64 are supported (little endian). | ||
Adding other architectures that are supported by QNX Neutrino is possible. | ||
|
||
The standard library does not yet support QNX Neutrino. Therefore, only `no_std` code can | ||
be compiled. | ||
|
||
`core` and `alloc` (with default allocator) are supported. | ||
|
||
Applications must link against `libc.so` (see example). This is required because applications | ||
always link against the `crt` library and `crt` depends on `libc.so`. | ||
|
||
The correct version of `qcc` must be available by setting the `$PATH` variable (e.g. by sourcing `qnxsdp-env.sh` of the | ||
QNX Neutrino toolchain). | ||
|
||
### Small example application | ||
|
||
```rust | ||
#![no_std] | ||
#![no_main] | ||
#![feature(lang_items)] | ||
|
||
// We must always link against libc, even if no external functions are used | ||
// "extern C" - Block can be empty but must be present | ||
#[link(name = "c")] | ||
extern "C" { | ||
pub fn printf(format: *const core::ffi::c_char, ...) -> core::ffi::c_int; | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize { | ||
const HELLO: &'static str = "Hello World, the answer is %d\n\0"; | ||
unsafe { | ||
printf(HELLO.as_ptr() as *const _, 42); | ||
} | ||
0 | ||
} | ||
|
||
use core::panic::PanicInfo; | ||
|
||
#[panic_handler] | ||
fn panic(_panic: &PanicInfo<'_>) -> ! { | ||
loop {} | ||
} | ||
|
||
#[lang = "eh_personality"] | ||
#[no_mangle] | ||
pub extern "C" fn rust_eh_personality() {} | ||
``` | ||
|
||
The QNX Neutrino support of Rust has been tested with QNX Neutrino 7.1. | ||
|
||
There are no further known requirements. | ||
|
||
## Conditional compilation | ||
|
||
For conditional compilation, following QNX Neutrino specific attributes are defined: | ||
|
||
- `target_os` = `"nto"` | ||
- `target_env` = `"nto71"` (for QNX Neutrino 7.1) | ||
|
||
## Building the target | ||
|
||
1. Create a `config.toml` | ||
|
||
Example content: | ||
|
||
```toml | ||
profile = "compiler" | ||
changelog-seen = 2 | ||
``` | ||
|
||
2. Compile the Rust toolchain for an `x86_64-unknown-linux-gnu` host (for both `aarch64` and `x86_64` targets) | ||
|
||
Run the following: | ||
|
||
```bash | ||
env \ | ||
CC_aarch64-unknown-nto-qnx7.1.0="qcc" \ | ||
CFLAGS_aarch64-unknown-nto-qnx7.1.0="-Vgcc_ntoaarch64le_cxx" \ | ||
CXX_aarch64-unknown-nto-qnx7.1.0="qcc" \ | ||
AR_aarch64_unknown_nto_qnx7.1.0="ntoaarch64-ar" \ | ||
CC_x86_64-pc-nto-qnx7.1.0="qcc" \ | ||
CFLAGS_x86_64-pc-nto-qnx7.1.0="-Vgcc_ntox86_64_cxx" \ | ||
CXX_x86_64-pc-nto-qnx7.1.0="qcc" \ | ||
AR_x86_64_pc_nto_qnx7.1.0="ntox86_64-ar" \ | ||
./x.py build --target aarch64-unknown-nto-qnx7.1.0 --target x86_64-pc-nto-qnx7.1.0 --target x86_64-unknown-linux-gnu rustc library/core library/alloc/ | ||
``` | ||
|
||
## Building Rust programs | ||
|
||
Rust does not yet ship pre-compiled artifacts for this target. To compile for this target, you must either build Rust with the target enabled (see "Building the target" above), or build your own copy of `core` by using | ||
`build-std` or similar. | ||
|
||
## Testing | ||
|
||
Compiled executables can directly be run on QNX Neutrino. | ||
|
||
## Cross-compilation toolchains and C code | ||
|
||
Compiling C code requires the same environment variables to be set as compiling the Rust toolchain (see above), to ensure `qcc` is used with proper arguments. To ensure compatibility, do not specify any further arguments that for example change calling conventions or memory layout. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.