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

Expected magic word 00 61 73 6d, found 21 3c 61 72 @+0 when loading .wasm file compiled from Go #35657

Closed
Mikerah opened this issue Nov 18, 2019 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@Mikerah
Copy link

Mikerah commented Nov 18, 2019

What version of Go are you using (go version)?

go1.13.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mikerah/snap/code/common/.cache/go-build"
GOENV="/home/mikerah/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mikerah/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build515948109=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I am attempting to compile a go package into webassembly. I had successfully followed the tutorial on the wiki page and applied the same steps to my particular use case. I was able to get a binary .wasm file. In order to do a quick check, I attempted to load the .wasm file into nodejs. When doing this, I get the following error:

(node:7918) UnhandledPromiseRejectionWarning: CompileError: WebAssembly.compile(): expected magic word 00 61 73 6d, found 21 3c 61 72 @+0

I compiled this this code into a .wasm file using GOOS=js GOARCH=wasm go build -o client.wasm. Then, I wrote a simply script to ensure that this was done correctly. The script is as follows:

import { readFileSync } from "fs";
async function createWebAssembly() {
   const buf = readFileSync("./client.wasm");
   const res = await WebAssembly.instantiate(new Uint8Array(buf).buffer);
}

createWebAssembly().then()

What did you expect to see?

Compiled program with warnings

What did you see instead?

See above error.

@agnivade
Copy link
Contributor

This is because you are compiling a non-main package, and thereby creating an object file, not an actual binary. It is valid for native architectures. But for wasm, you cannot do much with an object file. Please import the client package into a main package and build a binary.

Let us know if you still face issues.

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 18, 2019
@Mikerah
Copy link
Author

Mikerah commented Nov 18, 2019

Thank you very much for your response. That helps a lot.
Where can I find more information about this particular quirk? I didn't see it in the WebAssembly wiki and it would help a lot.

@Mikerah Mikerah closed this as completed Nov 18, 2019
@agnivade
Copy link
Contributor

Feel free to add it in the wiki.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants