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

Conversation

flba-eb
Copy link
Contributor

@flba-eb flba-eb commented Nov 29, 2024

Changes of this pull request:

  1. Refactor code for qnx nto targets to share more code in file nto_qnx.rs

  2. Add support for an additional network stack on nto qnx 7.1.

    QNX 7.1 supports two network stacks:

    1. io-pkt, which is default
    2. io-sock, which is optional on 7.1 but default in QNX 8.0

    As one can see in the io-sock migration notes, this changes the libc API in a way similar to e.g. linux-gnu vs. linux-musl.

    This change adds a new target which has a different value for target_env, so that e.g. libc can distinguish between both APIs.

  3. Add initial support for QNX 8.0, thanks @AkhilTThomas. As it turned out, the problem with forking many processes still exists in QNX 8.0. Because if this, we are now using it for any QNX version (i.e. not check for target_env anymore).

@rustbot label +O-neutrino
CC: @jonathanpallant @japaric @gh-tr @AkhilTThomas

@rustbot
Copy link
Collaborator

rustbot commented Nov 29, 2024

r? @pnkfelix

rustbot has assigned @pnkfelix.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. O-neutrino OS: QNX Neutrino, a POSIX-compatible real-time operating system labels Nov 29, 2024
@rust-log-analyzer

This comment has been minimized.

@flba-eb flba-eb force-pushed the add_nto_qnx71_iosock_support branch from 96a91e2 to 6116b6a Compare November 29, 2024 14:13
@rust-log-analyzer

This comment has been minimized.

@jonathanpallant
Copy link
Contributor

So, first up, excellent! The AWS QNX Neutrino 7.1.0 AMIs appears to use iosock and so I have to keep copying over libsocket.so.3 to run Rust code there. With this change hopefully I won't.

However, I note that there are currently no five-part-triples in the target list, so this would be the first. Perhaps aarch64-unknown-nto-qnx710_iosock would be better.

Will there be a x86_64-unknown-nto-qnx710_iosock to match?

@flba-eb

This comment was marked as resolved.

@flba-eb
Copy link
Contributor Author

flba-eb commented Nov 29, 2024

So, first up, excellent! The AWS QNX Neutrino 7.1.0 AMIs appears to use iosock and so I have to keep copying over libsocket.so.3 to run Rust code there. With this change hopefully I won't.

Beware that version 3 and 4 have different APIs -- they may seem to work, but there might be subtle issues up to undefined behavior.

However, I note that there are currently no five-part-triples in the target list, so this would be the first. Perhaps aarch64-unknown-nto-qnx710_iosock would be better.

Very good idea -- I found it confusing that target_env uses an underscore while the target name does not. I will rename it!

Will there be a x86_64-unknown-nto-qnx710_iosock to match?

Not planned so far, but should be quite easy to do. How big is the need for it?

@jonathanpallant
Copy link
Contributor

How big is the need for it?

No idea. Who was asking for this target?

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@flba-eb

This comment was marked as resolved.

@jonathanpallant
Copy link
Contributor

I was thinking to use an obvious dummy value rather than panicking if the environment variable isn't set. But maybe the project people have a better idea.

Are there another other targets that need to read environment variables?

@flba-eb

This comment was marked as resolved.

@flba-eb flba-eb force-pushed the add_nto_qnx71_iosock_support branch from 5051c34 to 00079dc Compare November 29, 2024 15:42
@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr mentioned this pull request Nov 29, 2024
@flba-eb flba-eb force-pushed the add_nto_qnx71_iosock_support branch 6 times, most recently from 72b6642 to 32310c3 Compare November 29, 2024 17:38
@rust-log-analyzer

This comment has been minimized.

@flba-eb flba-eb force-pushed the add_nto_qnx71_iosock_support branch from 519c76c to 80d6d03 Compare December 10, 2024 08:03
@flba-eb flba-eb marked this pull request as ready for review December 10, 2024 08:04
@flba-eb flba-eb changed the title Support Neutrino QNX 7.1 with io-sock network stack Support Neutrino QNX 7.1 with io-sock network stack and 8.0 Dec 10, 2024
@flba-eb
Copy link
Contributor Author

flba-eb commented Dec 10, 2024

As @pnkfelix left the compiler team, I would like to kindly ask @workingjubilee if they could have a look at this PR 😄 🎄 🎉

r? @workingjubilee

@rustbot rustbot assigned workingjubilee and unassigned pnkfelix Dec 10, 2024
@flba-eb flba-eb force-pushed the add_nto_qnx71_iosock_support branch from 80d6d03 to 6e472e4 Compare December 10, 2024 10:40
@rust-log-analyzer

This comment has been minimized.

@flba-eb flba-eb force-pushed the add_nto_qnx71_iosock_support branch from 6e472e4 to 9ec4be2 Compare December 10, 2024 10:53
@jonathanpallant
Copy link
Contributor

jonathanpallant commented Dec 12, 2024

On Windows 10, I get:

C:\Users\JonathanPallant\Documents\rust>C:\Users\JonathanPallant\AppData\Roaming\uv\python\cpython-3.13.1-windows-x86_64-none\python.exe .\x.py build --target=x86_64-pc-windows-msvc,x86_64-pc-nto-qnx800 rustc library/core library/alloc library/std

...

error occurred: unknown target `x86_64-pc-nto-qnx800`

Ah, do I still have to patch cc-rs?

@jonathanpallant
Copy link
Contributor

I patched cc-rs and it still doesn't know about QNX Neutrino 8.0. What's the best way to build this target right now?

@AkhilTThomas
Copy link
Contributor

AkhilTThomas commented Dec 12, 2024

I patched cc-rs and it still doesn't know about QNX Neutrino 8.0. What's the best way to build this target right now?

The patch i use is below.
However since generated.rs is generated this change is removed. details

diff --git a/src/target/generated.rs b/src/target/generated.rs
index 0c9b0ae..103bf36 100644
--- a/src/target/generated.rs
+++ b/src/target/generated.rs
@@ -352,6 +352,18 @@ pub(crate) const LIST: &[(&str, TargetInfo<'static>)] = &[
             unversioned_llvm_target: "aarch64-unknown-unknown",
         },
     ),
+    (
+        "aarch64-unknown-nto-qnx800",
+        TargetInfo {
+            full_arch: "aarch64",
+            arch: "aarch64",
+            vendor: "unknown",
+            os: "nto",
+            env: "nto80",
+            abi: "",
+            unversioned_llvm_target: "aarch64-unknown-unknown",
+        },
+    ),
     (
         "aarch64-unknown-openbsd",
         TargetInfo {
@@ -2896,6 +2908,18 @@ pub(crate) const LIST: &[(&str, TargetInfo<'static>)] = &[
             unversioned_llvm_target: "x86_64-pc-unknown",
         },
     ),
+    (
+        "x86_64-pc-nto-qnx800",
+        TargetInfo {
+            full_arch: "x86_64",
+            arch: "x86_64",
+            vendor: "pc",
+            os: "nto",
+            env: "nto80",
+            abi: "",
+            unversioned_llvm_target: "x86_64-pc-unknown",
+        },
+    ),

@jonathanpallant
Copy link
Contributor

OK, I got the QNX Neutrino 8.0 target for x86-64 compiled, but the linker is complaining about undefined reference to __my_thread_exit'`.

Do I need libc patches or something? Have the QNX Neutrino 8.0 targets been compiled/tested and if so, on which platforms were they tested?

@AkhilTThomas
Copy link
Contributor

AkhilTThomas commented Dec 12, 2024

OK, I got the QNX Neutrino 8.0 target for x86-64 compiled, but the linker is complaining about undefined reference to __my_thread_exit'`.

This is known (chicken and egg problem 🐔 🥚) , this can only be solved with a patch on libc , which currently gates these behind the target_env.

Do I need libc patches or something? Have the QNX Neutrino 8.0 targets been compiled/tested and if so, on which platforms were they tested?

I have compiled and run both aarch64 and x86-64 on qemu. I'm not aware of how to generate a nice report. (Please let me know if there is a way)
I'm attaching the reports on

My understanding is that once the targets are available here the libc changes can be pushed.

@jonathanpallant
Copy link
Contributor

Can you post a gist with a list of steps to reproduce so I can verify? Sounds like I need to point to a local copy of cc-rs with some patches (maybe someone can push those somewhere so we can see them ahead of the targets being regenerated) and a patch to point to a local copy of libc (or again, can someone push that somewhere).

In the absence of the Rust Project being able to build these targets in CI, I think it's important that the maintainers can at least verify that the target builds OK, and currently I cannot.

@jonathanpallant
Copy link
Contributor

Also, heads up - tomorrow is my last day of work in 2024, so if I can't do a build tomorrow, it'll have to wait until next year or you'll have to find other people with licences to verify this target change.

@AkhilTThomas
Copy link
Contributor

In the absence of the Rust Project being able to build these targets in CI, I think it's important that the maintainers can at least verify that the target builds OK, and currently I cannot.

Totally agree.
I had hoped to tackle the issue of __my_thread_exit at libc level. On deeper inspection i find that this special symbol is absent in nto80 (verified by comparing objdump of libc.a for nto71 and nto80).
Hence the fix would be to remove it's usage in backtrace.rs for nto80 targets.

@flba-eb Could you do this change ? Since i don't have push access here.

@flba-eb
Copy link
Contributor Author

flba-eb commented Dec 13, 2024

In the absence of the Rust Project being able to build these targets in CI, I think it's important that the maintainers can at least verify that the target builds OK, and currently I cannot.

Totally agree. I had hoped to tackle the issue of __my_thread_exit at libc level. On deeper inspection i find that this special symbol is absent in nto80 (verified by comparing objdump of libc.a for nto71 and nto80). Hence the fix would be to remove it's usage in backtrace.rs for nto80 targets.

@flba-eb Could you do this change ? Since i don't have push access here.

Please note that so far, QNX targets have always been added even if they were only no_std with panic = "abort". It is the logical (and required) step before other work can be done, like adding support to libc, cc, ctest2. Afterwards we can add support to backtrace and libstd. Currently, we only support libstd on QNX 7.1 but neither 7.0 nor 8.0. See nto-qnx.md. Most crate maintainers reject pull requests when they are using targets that are not yet supported by the compiler, i.e. we have to add the target configuration first.

My proposal:

  • Lets get this PR merged. It is okay that libstd and unwinding do not work yet.
  • Lets discuss the "quality assurance" done by QNX maintainers separately and document it in nto-qnx.md. It should be clear from the document what users can expect from us.

@jonathanpallant
Copy link
Contributor

ok, that makes sense - and it matches your table:

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

For the benefit of anyone who didn't scroll to the bottom of the comments or read the changes to the platform docs, could we edit the PR description to explain which of the four new targets being added has working libstd support, and for those that targets that don't, the follow up steps that are required to enable such support?

@flba-eb flba-eb changed the title Support Neutrino QNX 7.1 with io-sock network stack and 8.0 Support QNX 7.1 with io-sock support (libstd) and QNX 8.0 (no_std only) Dec 13, 2024
@flba-eb flba-eb changed the title Support QNX 7.1 with io-sock support (libstd) and QNX 8.0 (no_std only) Support QNX 7.1 with io-sock+libstd and QNX 8.0 (no_std only) Dec 13, 2024
@flba-eb flba-eb changed the title Support QNX 7.1 with io-sock+libstd and QNX 8.0 (no_std only) Support QNX 7.1 with io-sock+libstd and QNX 8.0 (no_std only) Dec 13, 2024
@flba-eb
Copy link
Contributor Author

flba-eb commented Dec 13, 2024

After discussing this with @thejpster and @AkhilTThomas, we came to the conclusion that from our point of view this change can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-neutrino OS: QNX Neutrino, a POSIX-compatible real-time operating system O-unix Operating system: Unix-like relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants