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

AArch64 register X18 is reserved for a platform register on VxWorks #135166

Closed
tekbar11 opened this issue Jan 6, 2025 · 2 comments · Fixed by #135184
Closed

AArch64 register X18 is reserved for a platform register on VxWorks #135166

tekbar11 opened this issue Jan 6, 2025 · 2 comments · Fixed by #135184
Labels
A-target-specs Area: Compile-target specifications C-bug Category: This is a bug. O-vxworks Target: when they made us, they called us Curiosity, and Spirit, and told us to tell you hello T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tekbar11
Copy link

tekbar11 commented Jan 6, 2025

Hi,

I'm building the 1.77.2 toolchain with aarch64-wrs-vxworks at work and I noticed strange behavior when running library tests, most notably some references being mysteriously set to garbage values like 0x0 or 0x10, causing segfaults. After investigation, it turns out that rustc was generating code using the X18/R18 register.

The VxWorks ARM Architecture Guide states:

The general purpose register X18 is reserved for a VxWorks platform register. User code must not use the X18 register.
Kernel and user applications must be compiled with the -ffixed-x18 compiler option (which is one of the defaults for VxWorks builds).

This is a bit vague, but there isn't more details and I'm not a VxWorks expert, but from what I can see the register seems to be used to store some kind of flag. This occurence is non deterministic, so it's hard to debug and observe what's going on, and it requires to build an executable that's complex enough to make the register allocator use X18.

AFAIK, this is the case for all versions of VxWorks 7 starting from 21.03 (Sorry I can't share any links, the VxWorks documentation is proprietary).

I think the Wind River (VxWorks' editor) compiler for C/C++ already reserve this register by default. GCC also does this by default since it supports VxWorks, however LLVM does not and so the aarch64-wrs-vxworks spec uses aarch64-unknown-linux-gnu as the LLVM target.

This issue does not seem to have been addressed upstream, but feel free to close it if this does not affect the newest version of Rust.

The easy fix for me was to simply add reserve-x18 to the list of target features, so I can take care of the MR if this is deemed reasonable.

Pinging @biabbas since they're listed as the maintainer for VxWorks target on the platform support page. 😄

@tekbar11 tekbar11 added the C-bug Category: This is a bug. label Jan 6, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 6, 2025
@workingjubilee workingjubilee added the O-vxworks Target: when they made us, they called us Curiosity, and Spirit, and told us to tell you hello label Jan 6, 2025
@workingjubilee
Copy link
Member

Yes, adding that implicitly seems good.

@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 6, 2025
@workingjubilee workingjubilee added the A-target-specs Area: Compile-target specifications label Jan 6, 2025
@biabbas
Copy link
Contributor

biabbas commented Jan 7, 2025

@tekbar11
Rustc would invoke windriver-c++ compiler internally, and wr-c++ would add this flag. But I think adding this to the target spec features would be good.

Edit:
wr-c++ is invoked as linker, so adding this flag to target spec seems necessary.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 8, 2025
…ingjubilee

Reserve x18 register for aarch64 wrs vxworks target

Fixes rust-lang#135166
r? `@workingjubilee`

Regards,
B I Abbas
@bors bors closed this as completed in 45250f3 Jan 8, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 8, 2025
Rollup merge of rust-lang#135184 - biabbas:reserve_18_aarch64, r=workingjubilee

Reserve x18 register for aarch64 wrs vxworks target

Fixes rust-lang#135166
r? ``@workingjubilee``

Regards,
B I Abbas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target-specs Area: Compile-target specifications C-bug Category: This is a bug. O-vxworks Target: when they made us, they called us Curiosity, and Spirit, and told us to tell you hello T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants