-
Notifications
You must be signed in to change notification settings - Fork 952
Crash with -target=wasi and -gc=leaking #2041
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
Comments
I've been looking into this with an execution trace from The
The equivalent code compiled with
The
I will attach these full files, or maybe stuff them in a gist. Update: https://gist.github.com/dgryski/0be7ddd4b13ad5ed2fc8bb201dee5ae9 |
Smallest reproducer so far:
Seems to be something related to the |
Current theory (via @aykevl):
|
When I compile with LLVM assertions enabled, I get the following crash:
So it appears there is an internal error. |
Looks like it's fixed with this patch: diff --git a/compiler/llvmutil/llvm.go b/compiler/llvmutil/llvm.go
index 21bc6c67..32691466 100644
--- a/compiler/llvmutil/llvm.go
+++ b/compiler/llvmutil/llvm.go
@@ -35,7 +35,14 @@ func CreateTemporaryAlloca(builder llvm.Builder, mod llvm.Module, t llvm.Type, n
ctx := t.Context()
targetData := llvm.NewTargetData(mod.DataLayout())
i8ptrType := llvm.PointerType(ctx.Int8Type(), 0)
- alloca = CreateEntryBlockAlloca(builder, t, name)
+ allocType := t
+ if targetData.TypeAllocSize(t) == 0 {
+ allocType = mod.Context().Int8Type()
+ }
+ alloca = CreateEntryBlockAlloca(builder, allocType, name)
+ if allocType != t {
+ alloca = builder.CreateBitCast(alloca, llvm.PointerType(t, 0), "")
+ }
bitcast = builder.CreateBitCast(alloca, i8ptrType, name+".bitcast")
size = llvm.ConstInt(ctx.Int64Type(), targetData.TypeAllocSize(t), false)
builder.CreateCall(getLifetimeStartFunc(mod), []llvm.Value{size, bitcast}, "") |
Looks like this makes zero-byte allocations |
Yeah. I'm now looking into a better fix for this. But it only increases my suspicion that this is actually a case of a LLVM bug that was fixed in LLVM 12: https://bugs.llvm.org/show_bug.cgi?id=49916 (fixed here: https://reviews.llvm.org/D101841). |
I made a better fix for the reproducer in #2041 (comment), but this variant still crashes with the same LLVM bug (send instead of receive): package main
import "time"
var ch = make(chan struct{})
func foo() {
time.Sleep(1)
close(ch)
}
func main() {
foo()
ch <- struct{}{}
} |
Fix: #2100 |
Released with 0.20.0 so now closing. Thank you! |
I'm experiencing some runtime issues with tinygo produced wasi with the
leaking
gc. I think I've been able to distill the issue down to its core.Source code:
Expected output:
Actual output (modified to remove the full file paths):
A few observations:
-opt=1
conservative
gc but that causes other issues for me.fmt.Println()
tolog.Println()
The text was updated successfully, but these errors were encountered: