Skip to content

cmd/link: on wasm, number of functions limited to 2^16 #64856

Open
@HarikrishnanBalagopal

Description

@HarikrishnanBalagopal

Overview

It seems to me that the size of a WASM function is limited to 2^16 = 65536 bytes?

ldr.SetSymValue(s, int64(funcValueOffset+va/ld.MINFUNC)<<16) // va starts at zero

This leads to a bunch of errors whenever using more than a few libraries in our WASM app
The code for our app is available in this branch https://github.com/konveyor/move2kube/blob/wasm/go.mod
The code is able to build using the official Go compiler WASIP1 support
https://github.com/konveyor/move2kube/blob/dec9d8da6e5f8882aacb46a8e5f784b96b42a3c6/Makefile#L45C2-L45C100

Issue

When we try to add the https://pkg.go.dev/go.starlark.net/starlark library then we get a bunch of compile errors

type:*github.com/mholt/archiver/v3.FileInfo: non-pc-relative relocation address for github.com/mholt/archiver/v3.(*FileInfo).ModTime is too big: 0x100c40000
type:*github.com/mholt/archiver/v3.FileInfo: non-pc-relative relocation address for github.com/mholt/archiver/v3.(*FileInfo).ModTime is too big: 0x100c40000
type:*github.com/mholt/archiver/v3.FileInfo: non-pc-relative relocation address for github.com/mholt/archiver/v3.(*FileInfo).Mode is too big: 0x100c60000
type:*github.com/mholt/archiver/v3.FileInfo: non-pc-relative relocation address for github.com/mholt/archiver/v3.(*FileInfo).Mode is too big: 0x100c60000
type:*github.com/mholt/archiver/v3.FileInfo: non-pc-relative relocation address for github.com/mholt/archiver/v3.(*FileInfo).Name is too big: 0x100c70000
type:*github.com/mholt/archiver/v3.FileInfo: non-pc-relative relocation address for github.com/mholt/archiver/v3.(*FileInfo).Name is too big: 0x100c70000
type:*github.com/mholt/archiver/v3.FileInfo: non-pc-relative relocation address for github.com/mholt/archiver/v3.(*FileInfo).Size is too big: 0x100c90000
/usr/local/go/pkg/tool/linux_amd64/link: too many errors
make: *** [Makefile:45: build] Error 1

Fix

Please remove this arbitrary limit on function size or at least provide a way to work around it. This is a severe limit on any real world app that will use many different libraries to implement various features.

The WASM page size is 65536 bytes https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Memory/Memory which is 2^16 and can be addressed with 16 bits. That might explain where this particular limit came from but it doesn't explain why a single function has to fit all inside of one WASM page. Especially since WASM functions live is a completely separate address space than the WASM linear memory.

Also see these comments:

Related

https://stackoverflow.com/questions/67294859/why-golang-limit-the-symbol-number-to-65535-while-compile-wasm-target
#7769
#7980
WebAssembly/design#1138

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.arch-wasmWebAssembly issuescompiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions