Skip to content

naked_asm! on wasm emits invalid assembly #135518

@tgross35

Description

@tgross35
Contributor
#![feature(asm_experimental_arch)]
#![feature(naked_functions)]

#[naked]
pub extern "C" fn foo() {
    unsafe { core::arch::naked_asm!("nop") }
}

This should work (at least, I don't know of any reason it shouldn't), but it looks like the way we wrap it is something that LLVM doesn't like (trimmed output):

error: unknown directive
note: instantiated into assembly here
1 | .pushsection .text._ZN7example3foo17h5bf07194c275cbceE,"ax", @progbits

warning: .size directive ignored for function symbols
7 | .size _ZN7example3foo17h5bf07194c275cbceE, . - _ZN7example3foo17h5bf07194c275cbceE

error: unknown directive
note: instantiated into assembly here
8 | .popsection

error: Unmatched block construct(s) at function end: function
note: instantiated into assembly here
9 |

IR for reference:

module asm ".pushsection .text.foo,\22ax\22, @progbits"
module asm ".balign 4"
module asm ".globl foo"
module asm ".type foo, @function"
module asm "foo:"
module asm "nop"
module asm ".size foo, . - foo"
module asm ".popsection"

I don't know enough about wasm to know what is correct here, but looking at some wasm codegen it seems like .pushsection should become .section, .popsection should be dropped, and we should emit .functype directives (e.g. .functype somefunc (f64) -> (f64))

https://rust.godbolt.org/z/re5sverch

cc @folkertdev for naked functions and @daxpedda for knowing more about wasm-asm

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 15, 2025
added
O-wasmTarget: WASM (WebAssembly), http://webassembly.org/
requires-nightlyThis issue requires a nightly compiler in some way.
A-inline-assemblyArea: Inline assembly (`asm!(…)`)
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 15, 2025
folkertdev

folkertdev commented on Jan 15, 2025

@folkertdev
Contributor

Yes this was just missed so far, and I agree that it should work.

Supporting wasm-asm appears mostly straightforward, but emitting .functype is a little tricky (and requires at least this bugfix). Anyway, I'm working on it.

added a commit that references this issue on Jan 21, 2025
fc5962d
added 3 commits that reference this issue on Jan 21, 2025
d0fb727
8395924
2990bdc
added a commit that references this issue on Jan 23, 2025
781e01f
added 2 commits that reference this issue on Jan 23, 2025
5c8786c
d9d8bde
added a commit that references this issue on Jan 24, 2025
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-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @folkertdev@tgross35@rustbot

      Issue actions

        `naked_asm!` on wasm emits invalid assembly · Issue #135518 · rust-lang/rust