1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:04:42 -07:00

cmd/link: fix name section of WebAssembly binary

Chrome and Node.js were not showing the names of WebAssembly
functions any more. This was due to the name section containing
names also for import functions, which is redundant.

Change-Id: I2f2b2d0b5bd7a59b34f108d2fd7b6ba2eb26f9c9
Reviewed-on: https://go-review.googlesource.com/118976
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Richard Musiol 2018-06-14 19:22:55 +02:00 committed by Brad Fitzpatrick
parent 2809b339b5
commit 4eb1c84752

View File

@ -177,7 +177,7 @@ func asmb(ctxt *ld.Link) {
writeCodeSec(ctxt, fns)
writeDataSec(ctxt)
if !*ld.FlagS {
writeNameSec(ctxt, append(hostImports, fns...))
writeNameSec(ctxt, len(hostImports), fns)
}
ctxt.Out.Flush()
@ -409,14 +409,14 @@ var nameRegexp = regexp.MustCompile(`[^\w\.]`)
// writeNameSec writes an optional section that assigns names to the functions declared by the "func" section.
// The names are only used by WebAssembly stack traces, debuggers and decompilers.
// TODO(neelance): add symbol table of DATA symbols
func writeNameSec(ctxt *ld.Link, fns []*wasmFunc) {
func writeNameSec(ctxt *ld.Link, firstFnIndex int, fns []*wasmFunc) {
sizeOffset := writeSecHeader(ctxt, sectionCustom)
writeName(ctxt.Out, "name")
sizeOffset2 := writeSecHeader(ctxt, 0x01) // function names
writeUleb128(ctxt.Out, uint64(len(fns)))
for i, fn := range fns {
writeUleb128(ctxt.Out, uint64(i))
writeUleb128(ctxt.Out, uint64(firstFnIndex+i))
writeName(ctxt.Out, fn.Name)
}
writeSecSize(ctxt, sizeOffset2)