Skip to content

Usage of curly braces in ARM assembly considered invalid #140963

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

Closed
mahircg-aws opened this issue May 13, 2025 · 4 comments
Closed

Usage of curly braces in ARM assembly considered invalid #140963

mahircg-aws opened this issue May 13, 2025 · 4 comments
Labels
C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.

Comments

@mahircg-aws
Copy link

ARM multi load/store instructions require curly braces to specify the target register range: https://developer.arm.com/documentation/ddi0406/c/Application-Level-Architecture/The-Instruction-Sets/Load-store-multiple-instructions?lang=en#:~:text=Load%20Multiple%20instructions%20load%20a,are%20consecutive%20word%2Daligned%20words.

The following inline assembly instruction requires curly braces as part of specifying the register range.

unsafe { asm!("stmib sp, {x0 - x15}",) }

During compilation, I get the following error.

error: invalid asm template string: expected `}`, found `-`
   --> firecrab/src/main.rs:386:34
    |
386 |     unsafe { asm!("stmib sp, {x0 - x15}",) }
    |                              -   ^ expected `}` in asm template string
    |                              |
    |                              because of this opening brace
    |
    = note: if you intended to print `{`, you can escape it using `{{`

Reading https://rust-lang.github.io/rfcs/2873-inline-asm.html#use-of-double-braces-in-the-template-string, it looks like the only usage for curly braces was for AVX extension in x86.

Same error is reported on assembly that is included in Rust world with core::arch::global_asm!(include_str!("asm.s"));

.macro asm_test
    stmib sp, {x0 - x15}

Is that a bug in the way the assembly blobs are parsed?

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (b19329a37 2024-11-21)
binary: rustc
commit-hash: b19329a37cedf2027517ae22c87cf201f93d776e
commit-date: 2024-11-21
host: aarch64-apple-darwin
release: 1.84.0-nightly
LLVM version: 19.1.4
@mahircg-aws mahircg-aws added the C-bug Category: This is a bug. label May 13, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 13, 2025
@taiki-e
Copy link
Member

taiki-e commented May 13, 2025

You have to use {{x0 - x15}} (double { and }) or raw option.

@mahircg-aws
Copy link
Author

I tried that, and it causes the following error. I think it interprets the instruction as a vector operation and expects vector registers.

error: <instantiation>:2:16: vector register expected
    stmib sp, {x0 - x15}
               ^

error: could not compile `bin` (bin "bin")

@taiki-e
Copy link
Member

taiki-e commented May 13, 2025

Ah, you are trying to use the A32/T32 instruction with A64. In other words, it is an instruction for 32-bit Arm (AArch32) and therefore not available for AArch64.

See also ISA documentation; stmib is included only in AArch32's:

@mahircg-aws
Copy link
Author

Yes, I've noticed that later on. I didn't realize it wasn't available until I used options(raw).

Closing this one, thanks for the pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.
Projects
None yet
Development

No branches or pull requests

3 participants