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

naked_asm! on wasm emits invalid assembly #135518

Closed
tgross35 opened this issue Jan 15, 2025 · 1 comment · Fixed by #135648
Closed

naked_asm! on wasm emits invalid assembly #135518

tgross35 opened this issue Jan 15, 2025 · 1 comment · Fixed by #135648
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tgross35
Copy link
Contributor

tgross35 commented Jan 15, 2025

#![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

@tgross35 tgross35 added the C-bug Category: This is a bug. label Jan 15, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 15, 2025
@tgross35 tgross35 added O-wasm Target: WASM (WebAssembly), http://webassembly.org/ requires-nightly This issue requires a nightly compiler in some way. A-inline-assembly Area: Inline assembly (`asm!(…)`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 15, 2025
@folkertdev
Copy link
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.

jhpratt added a commit to jhpratt/rust that referenced this issue Jan 21, 2025
support wasm inline assembly in `naked_asm!`

fixes rust-lang#135518

Webassembly was overlooked previously, but now `naked_asm!` and `#[naked]` functions work on the webassembly targets.

Or, they almost do right now. I guess this is no surprise, but the `wasm32-unknown-unknown` target causes me some trouble. I'll add some inline comments with more details.

r? `@bjorn3`

cc `@daxpedda,` `@tgross35`
jieyouxu added a commit to jieyouxu/rust that referenced this issue Jan 21, 2025
support wasm inline assembly in `naked_asm!`

fixes rust-lang#135518

Webassembly was overlooked previously, but now `naked_asm!` and `#[naked]` functions work on the webassembly targets.

Or, they almost do right now. I guess this is no surprise, but the `wasm32-unknown-unknown` target causes me some trouble. I'll add some inline comments with more details.

r? ``@bjorn3``

cc ``@daxpedda,`` ``@tgross35``
jieyouxu added a commit to jieyouxu/rust that referenced this issue Jan 21, 2025
support wasm inline assembly in `naked_asm!`

fixes rust-lang#135518

Webassembly was overlooked previously, but now `naked_asm!` and `#[naked]` functions work on the webassembly targets.

Or, they almost do right now. I guess this is no surprise, but the `wasm32-unknown-unknown` target causes me some trouble. I'll add some inline comments with more details.

r? ```@bjorn3```

cc ```@daxpedda,``` ```@tgross35```
jieyouxu added a commit to jieyouxu/rust that referenced this issue Jan 22, 2025
support wasm inline assembly in `naked_asm!`

fixes rust-lang#135518

Webassembly was overlooked previously, but now `naked_asm!` and `#[naked]` functions work on the webassembly targets.

Or, they almost do right now. I guess this is no surprise, but the `wasm32-unknown-unknown` target causes me some trouble. I'll add some inline comments with more details.

r? ````@bjorn3````

cc ````@daxpedda,```` ````@tgross35````
jhpratt added a commit to jhpratt/rust that referenced this issue Jan 23, 2025
support wasm inline assembly in `naked_asm!`

fixes rust-lang#135518

Webassembly was overlooked previously, but now `naked_asm!` and `#[naked]` functions work on the webassembly targets.

Or, they almost do right now. I guess this is no surprise, but the `wasm32-unknown-unknown` target causes me some trouble. I'll add some inline comments with more details.

r? `````@bjorn3`````

cc `````@daxpedda,````` `````@tgross35`````
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 23, 2025
support wasm inline assembly in `naked_asm!`

fixes rust-lang#135518

Webassembly was overlooked previously, but now `naked_asm!` and `#[naked]` functions work on the webassembly targets.

Or, they almost do right now. I guess this is no surprise, but the `wasm32-unknown-unknown` target causes me some trouble. I'll add some inline comments with more details.

r? ``````@bjorn3``````

cc ``````@daxpedda,`````` ``````@tgross35``````
@bors bors closed this as completed in d9d8bde Jan 24, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 24, 2025
Rollup merge of rust-lang#135648 - folkertdev:naked-asm-wasm, r=bjorn3

support wasm inline assembly in `naked_asm!`

fixes rust-lang#135518

Webassembly was overlooked previously, but now `naked_asm!` and `#[naked]` functions work on the webassembly targets.

Or, they almost do right now. I guess this is no surprise, but the `wasm32-unknown-unknown` target causes me some trouble. I'll add some inline comments with more details.

r? ```````@bjorn3```````

cc ```````@daxpedda,``````` ```````@tgross35```````
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jan 25, 2025
support wasm inline assembly in `naked_asm!`

fixes rust-lang/rust#135518

Webassembly was overlooked previously, but now `naked_asm!` and `#[naked]` functions work on the webassembly targets.

Or, they almost do right now. I guess this is no surprise, but the `wasm32-unknown-unknown` target causes me some trouble. I'll add some inline comments with more details.

r? ```````@bjorn3```````

cc ```````@daxpedda,``````` ```````@tgross35```````
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this issue Jan 27, 2025
support wasm inline assembly in `naked_asm!`

fixes rust-lang/rust#135518

Webassembly was overlooked previously, but now `naked_asm!` and `#[naked]` functions work on the webassembly targets.

Or, they almost do right now. I guess this is no surprise, but the `wasm32-unknown-unknown` target causes me some trouble. I'll add some inline comments with more details.

r? ```````@bjorn3```````

cc ```````@daxpedda,``````` ```````@tgross35```````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants