Open
Description
Given this input:
target triple = "wasm32-unknown-unknown"
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
define void @foo(ptr %a) #0 {
call void %a()
ret void
}
attributes #0 = { "target-cpu"="mvp" }
Locally I see:
$ llvm-as wat.ll
$ wasm-ld wat.bc -o foo.wasm --no-entry --export foo
$ wasm-tools validate -f=-reference-types foo.wasm
error: func 0 failed to validate
Caused by:
0: zero byte expected (at offset 0x4b)
This issue is a reduction of rust-lang/rust#130604 and is where a user is trying to disable reference types for their entire compilation and use LTO as well, but it looks like the "target-cpu"
isn't taking effect with wasm-ld
.
cc @sbc100 do you know what might be causing this?
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
reference-types
feature for wasm32 target with-C linker-plugin-lto
flag rust-lang/rust#130604sbc100 commentedon Sep 20, 2024
That does seem wrong. Just to confirm, if you compile to and object file (not a .bc file) this doesn't fail?
alexcrichton commentedon Sep 20, 2024
Right yeah, this works ok:
Interestingly the
-mcpu=mvp
is required though. If I remove that flag then it additionally doesn't work. I forget all the ways that the CPU and such can be configured in LLVM, but I believe that passing-mcpu=mvp
mirrors what the Rust compiler does at least. (I'm mostly not sure how the CLI flag-mcpu=mvp
interacts with the"target-cpu"="mvp"
attribute on functions)llvmbot commentedon Sep 20, 2024
@llvm/issue-subscribers-lld-wasm
Author: Alex Crichton (alexcrichton)
Locally I see:
This issue is a reduction of rust-lang/rust#130604 and is where a user is trying to disable reference types for their entire compilation and use LTO as well, but it looks like the
"target-cpu"
isn't taking effect withwasm-ld
.cc @sbc100 do you know what might be causing this?
StackOverflowExcept1on commentedon Mar 5, 2025
@sbc100 Any updates on this bug?
sbc100 commentedon Mar 5, 2025
I cannot reproduce this anymore:
Also, the two binaries produced via LTO and non-LTO are identical for me:
Can either of you still reproduce this?
StackOverflowExcept1on commentedon Mar 5, 2025
@sbc100 With LLVM 20? As far as I know Rust has recently updated to LLVM 20.
sbc100 commentedon Mar 5, 2025
I only tested on tip-of-tree. I don't have LLVM 20 handy to test I'm afraid.
StackOverflowExcept1on commentedon Mar 5, 2025
I can confirm that this problem is solved at least in nightly Rust
alexcrichton commentedon Mar 5, 2025
Nice! Seems like this may have been fixed in the 19->20 interim, so closing.
StackOverflowExcept1on commentedon Mar 5, 2025
@alexcrichton @sbc100 I tried building more complex wasm and now it has
memory.fill
(bulk memory operations), although my target iswasm32v1-none
:alexcrichton commentedon Mar 5, 2025
There's a lot of possible reasons for where that might be coming from, so perhaps it's best to continue the discussion elsewhere given that this specific issue seems to have been fixed? Maybe on your project's issue tracker or similar?
StackOverflowExcept1on commentedon Apr 23, 2025
@sbc100 Can we reopen this? I'm seeing similar problem again, but so far I have not been able to minimize it. I wrote the steps to reproduce here: rust-lang/rust#140174 (comment).
wasm_program.ll
target_features
contains many features that should not appear inwasm32v1-none
(mvp
+mutable-globals
)