Skip to content

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

Open

Description

@jethrogb

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

Activity

  1. jethrogb commented on May 7, 2021

    @jethrogb
    ContributorAuthor

    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

  2. added
    A-inline-assemblyArea: Inline assembly (`asm!(…)`)
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    F-asm`#![feature(asm)]` (not `llvm_asm`)
    on May 7, 2021
  3. bstrie commented on May 7, 2021

    @bstrie
    Contributor

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

  4. added a commit that references this issue on Jun 9, 2021
  5. Lokathor commented on Jun 24, 2022

    @Lokathor
    Contributor

    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).

  6. added a commit that references this issue on Dec 26, 2022
  7. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 5, 2023
  8. oxalica commented on Mar 12, 2025

    @oxalica
    Contributor

    Some update in LLVM: llvm/llvm-project#81048
    It tried to correctly handle clobbering of BX and BP on x86_64, but turns out the patch does not keep stack alignment correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-inline-assemblyArea: Inline assembly (`asm!(…)`)F-asm`#![feature(asm)]` (not `llvm_asm`)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions