Commit 4eb1c847 authored by Richard Musiol's avatar Richard Musiol Committed by Brad Fitzpatrick

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/118976Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 2809b339
......@@ -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)
......
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