Skip to content

global_asm! macro causes non-fatal errors to be printed during compilation for some RISC-V extension instructions when targeting the GC extensions #80608

Description

@repnop

I'm currently using the asm! macro on the riscv64gc-unknown-none-elf target, and have been getting some "errors" for a while about instructions requiring extensions -- except that GC includes the extensions of the instructions I'm using (IMAFDC). So far I've seen errors for F, D, and A instructions, everything else seems to be fine that I've used so far. Despite them being reported as errors, the build still succeeds however. @nbdd0121 suggested this may be an LLVM bug.

Example:

error: instruction requires the following: 'D' (Double-Precision Floating-Point)
        fsd f0, 248(sp)
        ^
error: instruction requires the following: 'A' (Atomic Instructions)
        sc.d zero, zero, 0(sp)
        ^

Activity

  1. added
    A-inline-assemblyArea: Inline assembly (`asm!(…)`)
    F-asm`#![feature(asm)]` (not `llvm_asm`)
    O-riscvTarget: RISC-V architecture
    on Jan 2, 2021
  2. Amanieu commented on Jan 2, 2021

    @Amanieu
    Member

    I can't seem to reproduce this: https://rust.godbolt.org/z/5hW8jn

  3. repnop commented on Jan 2, 2021

    @repnop
    ContributorAuthor

    Ah, finally was able to reproduce it, looks like its not asm! but global_asm! (I never made the connection between the output and global_asm!, I assumed it affected both since I don't use those instructions in non-global_asm! code), so I'll correct the title. It also requires the --emit=dep-info,link argument to be passed to rustc, at which point you can see all of the errors, here's a godbolt link: https://rust.godbolt.org/z/KreW3M

  4. changed the title [-]`asm!` macro causes non-fatal errors to be printed during compilation for some RISC-V extension instructions when targeting the GC extensions[/-] [+]`global_asm!` macro causes non-fatal errors to be printed during compilation for some RISC-V extension instructions when targeting the GC extensions[/+] on Jan 2, 2021
  5. usamoi commented on Apr 10, 2022

    @usamoi
    Contributor

    I saw error: instruction requires the following: 'D' (Double-Precision Floating-Point) in my global_asm on the riscv64gc-unknown-none-elf target, too, but only in release mode.

  6. Amanieu commented on Apr 10, 2022

    @Amanieu
    Member

    I still don't know what the cause of this problem is (it seems to be in LLVM?). However I have found a workaround: you need to add .attribute arch, "rv64gc" to the assembly code to enable the f and d features in the assembler.

  7. deepaksirone commented on Mar 5, 2023

    @deepaksirone

    I see the following in a release build with global_asm!:

    error: instruction requires the following: 'A' (Atomic Instructions)
            amoswap.d.aq t0, t0, (t1)
            ^
    error: instruction requires the following: 'M' (Integer Multiplication and Division) or 'Zmmul' (Integer Multiplication)
            mul t1, a3, t2
    
  8. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    on Apr 6, 2023
  9. Amanieu commented on Apr 6, 2023

    @Amanieu
    Member
  10. 35 remaining items

  11. jonathanpallant commented on Jul 3, 2026

    @jonathanpallant
    Contributor

    LLVM now supports setting target features on asm blocks (llvm/llvm-project#204548 was merged today).

    I'm not sure whether Rust would fill that in for you, or if we require users to do it (in which case it doesn't seem a lot better than just manually specifying .arch v8m or something in the assembly text itself).

  12. folkertdev commented on Jul 3, 2026

    @folkertdev
    Contributor

    If I read it right, a backend can now override functions to enter and exit a context with particular target features (emitTargetFeaturePush and emitTargetFeaturePop). So, the relevant backends would need to add support (currently only the riscv backend overrides this, so a follow-up is needed still). Then, from what I can tell the functionality is also not yet exposed via the C api.

    Anyhow, this is all in LLVM, so for rust it's just a matter of forwarding the correct target features. We'd at least forward the target features that are statically enabled. We'll need to figure something out if we want something more custom than that.

  13. nikic commented on Jul 3, 2026

    @nikic
    Contributor

    The target feature push/pop is only relevant when round-tripping through assembly. When going directly to machine code, just specifying the target features on the global asm would be sufficient. That's either the global features, or the target features on a naked function (if that's something we support).

  14. folkertdev commented on Jul 3, 2026

    @folkertdev
    Contributor

    or the target features on a naked function (if that's something we support).

    It's something we'd like to support

    It sounds like we'd already get the push/pop behavior of features that we want then? (i.e. features enabled in an module-level assembly block do not "leak" into other code). I tried to implement that manually at some point but got kind of stuck, see #137720.

  15. added 3 commits that reference this issue on Aug 28, 2026
  16. added a commit that references this issue on Aug 29, 2026
  17. added a commit that references this issue on Aug 29, 2026
  18. added a commit that references this issue on Aug 29, 2026
  19. added a commit that references this issue on Oct 4, 2026
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!(…)`)C-external-bugCategory: issue that is caused by bugs in software beyond our controlF-asm`#![feature(asm)]` (not `llvm_asm`)O-riscvTarget: RISC-V architecture

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions