3

did somebody tried to compile Rust code for QNX? I would love switching from C++ to Rust, but have to support QNX.

Compiling for Linux (same architecture) and trying to link with QNX linker causes a lot of linking issues (not sure if this makes any sense at all):

undefined reference to `_Unwind_Backtrace'
undefined reference to `_Unwind_DeleteException'
undefined reference to `_Unwind_GetDataRelBase'
undefined reference to `_Unwind_GetIP'
undefined reference to `_Unwind_GetIPInfo'
undefined reference to `_Unwind_GetLanguageSpecificData'
undefined reference to `_Unwind_GetRegionStart'
undefined reference to `_Unwind_GetTextRelBase'
undefined reference to `_Unwind_RaiseException'
undefined reference to `_Unwind_Resume'
undefined reference to `_Unwind_SetGR'
undefined reference to `_Unwind_SetIP'
undefined reference to `__errno_location'
undefined reference to `__xpg_strerror_r'
undefined reference to `fstat64'
undefined reference to `memrchr'
undefined reference to `open64'
undefined reference to `pthread_getattr_np'
undefined reference to `sigaltstack'
undefined reference to `syscall'
undefined references to `_Unwind_Resume' follow

Would it be feasible to port rustc to QNX with the (rather old) C/C++ compiler from QNX, or would we also need to port the LLVM used by rustc to QNX?

Herohtar
  • 5,347
  • 4
  • 31
  • 41
flba
  • 379
  • 1
  • 11
  • Did you try to build the whole stdlib? Did you ensure the qnx libc is being linked properly? Can you get a barebones no std project to build? – Aiden4 Oct 12 '21 at 14:22
  • I tried several qcc options for linking against libc (QNX provides several ones). I neither compiled stdlib from Rust nor from QNX; which one are you referring to (Rust or QNX)? – flba Oct 12 '21 at 14:38
  • I'm referring to rust- you almost certainly want to use cargo's [`build-std`](https://docs.rust-embedded.org/embedonomicon/custom-target.html) feature to build Rust's stdlib for qnx. Also, just using libcore + liballoc + libc will probably good enough if you can't get the full stdlib to build. – Aiden4 Oct 12 '21 at 16:05
  • I managed to compile rust for Linux using `x.py` (just to ensure that I've all required tools available). Now I'm not sure how to proceed. Any suggestion like where to seek help or is there a manual how to port the compiler (which I wasn't able to find)? (I mean besides the link you've already provided: thanks!) – flba Oct 15 '21 at 14:09
  • You don't have to build the entire toolchain- just build the standard library for the QNX target would be good enough. [This link](https://docs.rust-embedded.org/embedonomicon/custom-target.html) has instructions on how to create a custom target and build the standard library with cargo (does require nightly). – Aiden4 Oct 15 '21 at 14:23
  • I guess I need to understand better what the underlying problem is: I found the location where e.g. `fstat64` is called, i.e. from the file `fs.rs`. As this is a rust file and not a C file that I can compile with the QNX compiler, how can I make it compatible with QNX? Is the signature of `fstat64` wrong for QNX and I need to adjust it? – flba Oct 16 '21 at 16:59
  • `fstat64` comes from libc, make sure that the QNX libc is being linked correctly. – Aiden4 Oct 16 '21 at 18:12
  • Running a very simple no_std main function (only returning a value) did work (linking at running on QNX). I guess I need to figure out how to link Rusts stdlib correctly. Do you think it is still required to compile stdlib for QNX, or is this only a linker parameter issue? – flba Oct 16 '21 at 18:39
  • libcore and liballoc should build just fine without libc. You should use target options `post-link-args` or `pre-link-args` to tell the QNX linker to link against the proper libc. – Aiden4 Oct 16 '21 at 19:09
  • I've created a file `aarch64-unknown-qnx-gnu.json`, derived from the linux version. When trying to compile the [no_std program](https://docs.rust-embedded.org/embedonomicon/custom-target.html) with `cargo size --target aarch64-unknown-qnx-gnu --bin app`, cargo complains with `no such subcommand: size`. Trying to compile inside the rust source code (master), cargo reports `failed to load manifest for workspace member rust_src/src/tools/rust-installer` (I've tried it in several directories). – flba Oct 18 '21 at 17:59
  • Rustc version is `rustc 1.57.0-nightly (c1026539b 2021-10-15)` – flba Oct 18 '21 at 18:11
  • `cargo size` isn't a thing. Do you want `cargo build`? – Aiden4 Oct 18 '21 at 21:08
  • Are you building your rust::c interface using the qnx header files? `Fstat64()`, for example, takes a different `struct stat64` layout on qnx than on linux. – mevets Oct 29 '21 at 11:42
  • It seems I'm missing some information; I tried from scratch today: [rust compiler code 9f13](https://github.com/rust-lang/rust/commit/9f13083542cb2b9fce83ed8a50238e4a6386820f), target file `aarch64-unknown-qnx-gnu.json` created as described in [The Embedonomicon](https://docs.rust-embedded.org/embedonomicon/custom-target.html), basically a copy of AArch64-Linux, then I ran `./x.py build --target aarch64-unknown-qnx-gnu.json`. This failes compiling `library/stdarch/crates/std_detect/src/detect/cache.rs`, and I'm not sure it even compiles for AArch64. – flba Oct 30 '21 at 17:21
  • My plan was to build for AArch64-Linux first (no changes in compiler) and adapt the code to the libc API as soon as this compiles. Does this make sense? Should I start compiling without `--target aarch64-unknown-qnx-gnu.json`? – flba Oct 30 '21 at 17:24

0 Answers0