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

Failed to assemble on macOS #1544

Open
thewh1teagle opened this issue Nov 19, 2024 · 1 comment
Open

Failed to assemble on macOS #1544

thewh1teagle opened this issue Nov 19, 2024 · 1 comment
Labels
C-bug Category: This is a bug. O-arm Target: ARM processors (arm, thumb and AArch64 targets)

Comments

@thewh1teagle
Copy link

thewh1teagle commented Nov 19, 2024

macOS aarch64 m1

cargo new project
cd project
cargo add half
CARGO_PROFILE_DEV_CODEGEN_BACKEND="cranelift" cargo +nightly build -Zcodegen-backend

Error:

   Compiling cfg-if v1.0.0
   Compiling half v2.4.1
error: invalid operand for instruction
  |
note: instantiated into assembly here
 --> <inline asm>:8:9
  |
8 |     ldr v1, [x19, 0x0]
  |         ^

error: invalid operand for instruction
   |
note: instantiated into assembly here
  --> <inline asm>:10:9
   |
10 |     str v0, [x19, 0x0]
   |         ^

error: invalid operand for instruction
   |
note: instantiated into assembly here
  --> <inline asm>:22:9
   |
22 |     ldr v1, [x19, 0x0]
   |         ^

error: invalid operand for instruction
   |
note: instantiated into assembly here
  --> <inline asm>:24:9
   |
24 |     str v0, [x19, 0x0]
   |         ^

error: invalid operand for instruction
   |
note: instantiated into assembly here
  --> <inline asm>:36:9
   |
36 |     ldr v1, [x19, 0x0]
   |         ^

error: invalid operand for instruction
   |
note: instantiated into assembly here
  --> <inline asm>:38:9
   |
38 |     str v0, [x19, 0x0]
   |         ^

error: invalid operand for instruction
   |
note: instantiated into assembly here
  --> <inline asm>:50:9
   |
50 |     ldr v1, [x19, 0x0]
   |         ^

error: invalid operand for instruction
   |
note: instantiated into assembly here
  --> <inline asm>:51:9
   |
51 |     ldr v2, [x19, 0x10]
   |         ^

error: invalid operand for instruction
   |
note: instantiated into assembly here
  --> <inline asm>:55:9
   |
55 |     str v1, [x19, 0x0]
   |         ^

error: aborting due to 9 previous errors

error: Failed to assemble `.globl ___inline_asm_half__271c5a82f56fe67a_cgu__0_n0
       ___inline_asm_half__271c5a82f56fe67a_cgu__0_n0:
           stp fp, lr, [sp, #-32]!
           mov fp, sp
           str x19, [sp, #24]
           mov x19, x0
           ldr v1, [x19, 0x0]
       fcvt s0, h1
           str v0, [x19, 0x0]
           ldr x19, [sp, #24]
           ldp fp, lr, [sp], #32
           ret
       
       
       .globl ___inline_asm_half__271c5a82f56fe67a_cgu__0_n1
       ___inline_asm_half__271c5a82f56fe67a_cgu__0_n1:
           stp fp, lr, [sp, #-32]!
           mov fp, sp
           str x19, [sp, #24]
           mov x19, x0
           ldr v1, [x19, 0x0]
       fcvt h0, s1
           str v0, [x19, 0x0]
           ldr x19, [sp, #24]
           ldp fp, lr, [sp], #32
           ret
       
       
       .globl ___inline_asm_half__271c5a82f56fe67a_cgu__0_n2
       ___inline_asm_half__271c5a82f56fe67a_cgu__0_n2:
           stp fp, lr, [sp, #-32]!
           mov fp, sp
           str x19, [sp, #24]
           mov x19, x0
           ldr v1, [x19, 0x0]
       fcvtn v0.4h, v1.4s
           str v0, [x19, 0x0]
           ldr x19, [sp, #24]
           ldp fp, lr, [sp], #32
           ret
       
       
       .globl ___inline_asm_half__271c5a82f56fe67a_cgu__0_n3
       ___inline_asm_half__271c5a82f56fe67a_cgu__0_n3:
           stp fp, lr, [sp, #-32]!
           mov fp, sp
           str x19, [sp, #24]
           mov x19, x0
           ldr v1, [x19, 0x0]
           ldr v2, [x19, 0x10]
       fcvtn v0.2s, v1.2d
       fcvtn2 v0.4s, v2.2d
       fcvtn v1.4h, v0.4s
           str v1, [x19, 0x0]
           ldr x19, [sp, #24]
           ldp fp, lr, [sp], #32
           ret
       
       
       `

error: could not compile `half` (lib) due to 1 previous error

cargo build and cargo +nightly build works fine.

@bjorn3
Copy link
Member

bjorn3 commented Nov 21, 2024

Looks like on arm64 rustc will emit register names like v1 when no modifier is passed, while arm64 assembly requires specifying the width of the register like q1. https://github.com/rust-lang/rust/blob/0b1bf71a71c2a1d34c212285362530ec2c4e4775/compiler/rustc_target/src/asm/aarch64.rs#L207, https://github.com/rust-lang/rust/blob/0b1bf71a71c2a1d34c212285362530ec2c4e4775/compiler/rustc_codegen_llvm/src/asm.rs#L605

@bjorn3 bjorn3 added C-bug Category: This is a bug. O-arm Target: ARM processors (arm, thumb and AArch64 targets) labels Nov 21, 2024
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. O-arm Target: ARM processors (arm, thumb and AArch64 targets)
Projects
None yet
Development

No branches or pull requests

2 participants