Commit 8589f46f authored by Richard Musiol's avatar Richard Musiol Committed by Brad Fitzpatrick

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 2069543b
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"cmd/link/internal/sym" "cmd/link/internal/sym"
"io" "io"
"regexp" "regexp"
"runtime"
) )
const ( const (
...@@ -172,6 +173,7 @@ func asmb(ctxt *ld.Link) { ...@@ -172,6 +173,7 @@ func asmb(ctxt *ld.Link) {
writeBuildID(ctxt, buildid) writeBuildID(ctxt, buildid)
} }
writeGoVersion(ctxt)
writeTypeSec(ctxt, types) writeTypeSec(ctxt, types)
writeImportSec(ctxt, hostImports) writeImportSec(ctxt, hostImports)
writeFunctionSec(ctxt, fns) writeFunctionSec(ctxt, fns)
...@@ -220,6 +222,13 @@ func writeBuildID(ctxt *ld.Link, buildid []byte) { ...@@ -220,6 +222,13 @@ func writeBuildID(ctxt *ld.Link, buildid []byte) {
writeSecSize(ctxt, sizeOffset) 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 // writeTypeSec writes the section that declares all function types
// so they can be referenced by index. // so they can be referenced by index.
func writeTypeSec(ctxt *ld.Link, types []*wasmFuncType) { func writeTypeSec(ctxt *ld.Link, types []*wasmFuncType) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment