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

LLVM-reserved registers can't be used in inline assembly #85056

Open
jethrogb opened this issue May 7, 2021 · 3 comments
Open

LLVM-reserved registers can't be used in inline assembly #85056

jethrogb opened this issue May 7, 2021 · 3 comments
Labels
A-inline-assembly Area: inline asm!(..) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-asm `#![feature(asm)]` (not `llvm_asm`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jethrogb
Copy link
Contributor

jethrogb commented May 7, 2021

On several architectures, some registers are considered reserved by LLVM. These registers effectively can't be used by LLVM's inline assembly instruction as in input/output/clobber.

rustc currently disallows using these registers in asm!. This seems to be in contradiction with a stated goal in the RFC:

The intent is that support for asm! should be independent of the rustc back-end used

As such, I'd expect there to be no backend-specific limitations on inline assembly.

Current LLVM-reserved registers are:

  • x86: esi
  • x86-64: rbx
  • ARM: r7
@jethrogb
Copy link
Contributor Author

jethrogb commented May 7, 2021

At this time, solutions other than “fixing LLVM” seem non-exhaustive or non-trivial. See additional discussion at https://rust-lang.zulipchat.com/#narrow/stream/216763-project-inline-asm/topic/Handling.20clobbers

@jonas-schievink jonas-schievink added A-inline-assembly Area: inline asm!(..) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-asm `#![feature(asm)]` (not `llvm_asm`) labels May 7, 2021
@bstrie
Copy link
Contributor

bstrie commented May 7, 2021

Un-reserving registers can be done backwards-compatibly, yes? Presumably this does not block stabilization of asm!.

bors bot added a commit to fortanix/rust-sgx that referenced this issue Jun 9, 2021
336: Avoiding use of LLVM reserved register `rbx` r=jethrogb a=raoulstrackx

LLVM reserves register `rbx` in inline assembly (issue: #335). This PR avoids the use of this register until [rust-lang issue 85056](rust-lang/rust#85056) is merged

Co-authored-by: Raoul Strackx <raoul.strackx@fortanix.com>
@Lokathor
Copy link
Contributor

Lokathor commented Jun 24, 2022

It seems that r6 is also reserved by LLVM on ARM with both T32 and A32.

r7 seems to now be available with A32 (but still not T32).

sleffler added a commit to AmbiML/sparrow-cantrip-full that referenced this issue Nov 29, 2022
- correct seL4_Recv & co for MCS api difference
- split MCS- vs !MCS-syscall wrappers into separate files
- use split inout handling of src => badge

NB: does not compile with MCS because the reply parameter is passed in r6
    which is reserved on some arm targets; see rust-lang/rust#85056.

Bug: 247129956

Change-Id: Idbade9bc50fd7a0968fcbc79a7df69251a473921
GitOrigin-RevId: fe4205dc462031a2910656c3edf2b6811331351d
0xor0ne added a commit to 0xor0ne/debugoff that referenced this issue Dec 26, 2022
In armv7 register r7 is used to hold the syscall number.
However, r7 is also an LLVM reserved register ([1]) and cannot be used
as an input register.
As a temporary workaround we use r8 as temporary input register for
holding the syscall number and then copy r8 into r7 before the actual
system call.

[1] rust-lang/rust#85056
@Nilstrieb Nilstrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
Willmish pushed a commit to Willmish/cantrip that referenced this issue Feb 14, 2024
- correct seL4_Recv & co for MCS api difference
- split MCS- vs !MCS-syscall wrappers into separate files
- use split inout handling of src => badge

NB: does not compile with MCS because the reply parameter is passed in r6
    which is reserved on some arm targets; see rust-lang/rust#85056.

Bug: 247129956

Change-Id: Idbade9bc50fd7a0968fcbc79a7df69251a473921
XuShaohua added a commit to XuShaohua/nc that referenced this issue Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: inline asm!(..) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-asm `#![feature(asm)]` (not `llvm_asm`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants