mirror of
https://github.com/golang/go
synced 2024-11-23 10:50:09 -07:00
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: Agniva De Sarker <agniva.quicksilver@gmail.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
c19b7b23e5
commit
57662b1575
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user