From 4eb1c84752b8d3171be930abf4281080d639f634 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Thu, 14 Jun 2018 19:22:55 +0200 Subject: [PATCH] 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 --- src/cmd/link/internal/wasm/asm.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/link/internal/wasm/asm.go b/src/cmd/link/internal/wasm/asm.go index b7beaa5d2f..96d9cbd71e 100644 --- a/src/cmd/link/internal/wasm/asm.go +++ b/src/cmd/link/internal/wasm/asm.go @@ -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) -- 2.51.0