]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: fix name section of WebAssembly binary
authorRichard Musiol <mail@richard-musiol.de>
Thu, 14 Jun 2018 17:22:55 +0000 (19:22 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 15 Jun 2018 02:09:44 +0000 (02:09 +0000)
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>
src/cmd/link/internal/wasm/asm.go

index b7beaa5d2fcec8f78ffa28256e9a75e3a6d6119c..96d9cbd71efb1b47d6f2e932f32d27a58c601717 100644 (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)