Commit 57662b15 authored by Richard Musiol's avatar Richard Musiol Committed by Richard Musiol

cmd/link: add producer section to wasm binaries

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: default avatarAgniva De Sarker <agniva.quicksilver@gmail.com>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent c19b7b23
......@@ -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.
......
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