diff options
author | Richard Musiol <mail@richard-musiol.de> | 2018-08-02 22:39:00 +0200 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-08-02 20:56:11 +0000 |
commit | 8589f46fe07998bd3b27a0cebce2f428e68014e0 (patch) | |
tree | ce3b24602365eb635d6631a9c6e0b011b1b538cb | |
parent | 2069543bf11fe0432f51231c8a2cd1d4629f5a05 (diff) | |
download | go-8589f46fe07998bd3b27a0cebce2f428e68014e0.tar.gz go-8589f46fe07998bd3b27a0cebce2f428e68014e0.zip |
cmd/link/internal/wasm: add Go version as a custom wasm section
The interface between the wasm binary and wasm_exec.js is experimental
and likely to change in the future. Still, there are some early adopters
who experiment with non-web wasm runtimes. They can't use wasm_exec.js
and have to provide their own equivalent. Adding the Go version as a
custom wasm sections allows for them to support a stable Go version and
the latest devel at the same time.
Change-Id: I6d377bb0a0c33cb80e86dd15a34ddc9a70680227
Reviewed-on: https://go-review.googlesource.com/127597
Run-TryBot: Richard Musiol <neelance@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r-- | src/cmd/link/internal/wasm/asm.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cmd/link/internal/wasm/asm.go b/src/cmd/link/internal/wasm/asm.go index 7cc6bef6b7..bffbc7c8a6 100644 --- a/src/cmd/link/internal/wasm/asm.go +++ b/src/cmd/link/internal/wasm/asm.go @@ -11,6 +11,7 @@ import ( "cmd/link/internal/sym" "io" "regexp" + "runtime" ) const ( @@ -172,6 +173,7 @@ func asmb(ctxt *ld.Link) { writeBuildID(ctxt, buildid) } + writeGoVersion(ctxt) writeTypeSec(ctxt, types) writeImportSec(ctxt, hostImports) writeFunctionSec(ctxt, fns) @@ -220,6 +222,13 @@ func writeBuildID(ctxt *ld.Link, buildid []byte) { writeSecSize(ctxt, sizeOffset) } +func writeGoVersion(ctxt *ld.Link) { + sizeOffset := writeSecHeader(ctxt, sectionCustom) + writeName(ctxt.Out, "go.version") + ctxt.Out.Write([]byte(runtime.Version())) + writeSecSize(ctxt, sizeOffset) +} + // writeTypeSec writes the section that declares all function types // so they can be referenced by index. func writeTypeSec(ctxt *ld.Link, types []*wasmFuncType) { |