Code Monkey home page Code Monkey logo

Comments (7)

orsinium avatar orsinium commented on August 15, 2024

@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.

deadprogram avatar deadprogram commented on August 15, 2024

@orsinium can you please also try removing "-mno-bulk-memory"

from tinygo.

aykevl avatar aykevl commented on August 15, 2024

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.

orsinium avatar orsinium commented on August 15, 2024

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.

aykevl avatar aykevl commented on August 15, 2024

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.

orsinium avatar orsinium commented on August 15, 2024

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.

aykevl avatar aykevl commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.