]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: add producer section to wasm binaries
authorRichard Musiol <mail@richard-musiol.de>
Mon, 23 Sep 2019 22:48:39 +0000 (00:48 +0200)
committerRichard Musiol <neelance@gmail.com>
Sun, 29 Sep 2019 09:13:13 +0000 (09:13 +0000)
This change adds an optional "producer" section that reports the source
language and compiler version. See
https://github.com/WebAssembly/tool-conventions/blob/master/ProducersSection.md.

It also removes the now redundant "go.version" section.

Fixes #33295.

Change-Id: Ib4c80528728caf9e524fbd3f26822cbbc8b05a75
Reviewed-on: https://go-review.googlesource.com/c/go/+/196804
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/link/internal/wasm/asm.go

index 54b265cb19fdfa5118073d2d860755593c314293..ee0a5176acf3b8e0c23aa9e3f45ed4f807e82cc9 100644 (file)
@@ -11,7 +11,6 @@ import (
        "cmd/link/internal/sym"
        "io"
        "regexp"
-       "runtime"
 )
 
 const (
@@ -177,7 +176,6 @@ func asmb2(ctxt *ld.Link) {
                writeBuildID(ctxt, buildid)
        }
 
-       writeGoVersion(ctxt)
        writeTypeSec(ctxt, types)
        writeImportSec(ctxt, hostImports)
        writeFunctionSec(ctxt, fns)
@@ -188,6 +186,7 @@ func asmb2(ctxt *ld.Link) {
        writeElementSec(ctxt, uint64(len(hostImports)), uint64(len(fns)))
        writeCodeSec(ctxt, fns)
        writeDataSec(ctxt)
+       writeProducerSec(ctxt)
        if !*ld.FlagS {
                writeNameSec(ctxt, len(hostImports), fns)
        }
@@ -226,13 +225,6 @@ 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) {
@@ -488,6 +480,26 @@ func writeDataSec(ctxt *ld.Link) {
        writeSecSize(ctxt, sizeOffset)
 }
 
+// writeProducerSec writes an optional section that reports the source language and compiler version.
+func writeProducerSec(ctxt *ld.Link) {
+       sizeOffset := writeSecHeader(ctxt, sectionCustom)
+       writeName(ctxt.Out, "producers")
+
+       writeUleb128(ctxt.Out, 2) // number of fields
+
+       writeName(ctxt.Out, "language")     // field name
+       writeUleb128(ctxt.Out, 1)           // number of values
+       writeName(ctxt.Out, "Go")           // value: name
+       writeName(ctxt.Out, objabi.Version) // value: version
+
+       writeName(ctxt.Out, "processed-by")   // field name
+       writeUleb128(ctxt.Out, 1)             // number of values
+       writeName(ctxt.Out, "Go cmd/compile") // value: name
+       writeName(ctxt.Out, objabi.Version)   // value: version
+
+       writeSecSize(ctxt, sizeOffset)
+}
+
 var nameRegexp = regexp.MustCompile(`[^\w\.]`)
 
 // writeNameSec writes an optional section that assigns names to the functions declared by the "func" section.