Comments (7)
@deadprogram asked me for a smaller code to reproduce and without Rust.
main.go
:
package main
var data []byte
//go:export boot
func Boot() {
fileSize := 1
data = make([]byte, fileSize)
data[0] = 3
f(data)
}
//go:noinline
func f([]byte) {}
target.json
:
{
"llvm-target": "wasm32-unknown-unknown",
"cpu": "generic",
"features": "+mutable-globals,+nontrapping-fptoint,+sign-ext,+bulk-memory",
"build-tags": ["tinygo.wasm", "wasm_unknown"],
"goos": "linux",
"goarch": "arm",
"linker": "wasm-ld",
"rtlib": "compiler-rt",
"scheduler": "none",
"gc": "leaking",
"libc": "wasmbuiltins",
"cflags": ["-mno-bulk-memory", "-mnontrapping-fptoint", "-msign-ext"],
"ldflags": [
"--allow-undefined",
"--no-demangle",
"--initial-memory=65536",
"--max-memory=65536",
"--stack-first",
"--no-entry",
"-zstack-size=14752"
],
"extra-files": ["src/runtime/asm_tinygowasm.S"]
}
Running with wasmer:
wasmer run ./tinygo-gc-debug.wasm --entrypoint boot
Traceback:
error: RuntimeError: unreachable
at runtime.alloc (<module>[2]:0xe0)
at boot (<module>[3]:0xfa)
from tinygo.
@orsinium can you please also try removing "-mno-bulk-memory"
from tinygo.
Running with wasmer:
wasmer run ./tinygo-gc-debug.wasm --entrypoint boot
Don't specify a different entrypoint. This likely causes the crash you're seeing. Just let _start
be called (it initializes important data structures like the heap).
can you please also try removing
"-mno-bulk-memory"
That's unlikely to have an effect, the only thing it does is change whether LLVM is allowed to use bulk memory instructions (it doesn't affect memory layout).
from tinygo.
can you please also try removing "-mno-bulk-memory"
Doesn't help.
Just let _start be called (it initializes important data structures like the heap).
There is no _start
section in the generated wasm file:
❯ wasm-objdump -x --section=export ./tinygo-gc-debug.wasm
tinygo-gc-debug.wasm: file format wasm 0x1
Section Details:
Export[3]:
- memory[0] -> "memory"
- func[1] <_initialize> -> "_initialize"
- func[3] <boot> -> "boot"
Probably, because there is "--no-entry"
specified in the target file. If I try removing it:
wasm-ld: error: entry symbol not defined (pass --no-entry to suppress): _start
failed to run tool: wasm-ld
error: failed to link /tmp/tinygo180852312/main: exit status 1
from tinygo.
It looks like you've modified some internals of TinyGo and are reporting issues as a result of that.
If you want us to help, I suggest you use either one of the built-in targets (like -target=wasi
) or describe exactly the modifications you made and the platform you're targetting.
from tinygo.
The TinyGo compiler I use is not modified. I installed the artifact from this job: https://github.com/tinygo-org/tinygo/actions/runs/8469118660
I use a custom target.json
which is attached to the issue and in the comment above. The wasm-unknown
target expects the memory to be imported and the wasi
target cannot be used with the environment that I target.
$ tinygo build -target=wasm-unknown .
$ wasmer run ./tinygo-gc-debug.wasm --entrypoint boot
error: Unable to instantiate the WebAssembly module
╰─▶ 1: Error while importing "env"."memory": unknown import. Expected Memory(MemoryType { minimum: 2 pages, maximum: None, shared: false })
from tinygo.
Ok, in that case you need to make sure that the first thing that's called is _initialize
. This exported function needs to be called before anything else to initialize the heap and various other important data structures.
from tinygo.
Related Issues (20)
- tinygo can't compile GO app to wasm file HOT 2
- tinygo source displeases linters HOT 1
- What happened to `-wasm-abi=generic`? HOT 1
- Enhancing TinyGo Build-Tags with Board-Specific Feature Tags
- latest versioning of compatible matrix of tinygo/go HOT 2
- TinyGo Program blocks forever with os.Pipe, go proc, and a sleep; same program returns as expected with go
- Error to find build id on OpenBSD
- Unable to find headers for building HOT 2
- Undefined os/signal symbols
- First write to WS2812 Led 0 sets green to 0xff (seen on RP2040 boards) HOT 15
- Support LLVM 18 HOT 5
- `reflect.Type.NumMethod()` returns 0 for interface types, impacting CBOR unmarshalling
- Very long indexing in IDE GoLand.
- hid-keyboard not working on nvidia agx orin HOT 12
- Does tinygo not support TLS features?
- Compiling programs SIGKILL on latest arm mac HOT 1
- tinygo build -gc none fails HOT 2
- `Type.AssignableTo` panics with "reflect: unimplemented: AssignableTo with interface"
- Is there a GOMEMLIMIT analog in TinyGo? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinygo.