1
0
mirror of https://github.com/golang/go synced 2024-11-26 06:17:57 -07:00

cmd/link: increase reserved space for passing env on wasm

On wasm, the wasm_exec.js helper passes the command line arguments and
environment variables via a reserved space in the wasm linear memory.
Increase this reserved space from 4096 to 8192 bytes so more environment
variables can fit into the limit.

Later, after https://golang.org/cl/350737 landed, we can switch to the
WASI interface for getting the arguments and environment. This would
remove the limit entirely.

Fixes #49011

Change-Id: I48a6e952a97d33404ed692c98e9b49c5cd6b269b
Reviewed-on: https://go-review.googlesource.com/c/go/+/358194
Trust: Richard Musiol <neelance@gmail.com>
Run-TryBot: Richard Musiol <neelance@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Richard Musiol 2021-10-24 12:28:18 +02:00 committed by Richard Musiol
parent 8c94aa40e6
commit 252324e879
2 changed files with 6 additions and 5 deletions

View File

@ -519,9 +519,9 @@
// The linker guarantees global data starts from at least wasmMinDataAddr. // The linker guarantees global data starts from at least wasmMinDataAddr.
// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr. // Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
const wasmMinDataAddr = 4096 + 4096; const wasmMinDataAddr = 4096 + 8192;
if (offset >= wasmMinDataAddr) { if (offset >= wasmMinDataAddr) {
throw new Error("command line too long"); throw new Error("total length of command line and environment variables exceeds limit");
} }
this._inst.exports.run(argc, argv); this._inst.exports.run(argc, argv);

View File

@ -2442,10 +2442,11 @@ func splitTextSections(ctxt *Link) bool {
return (ctxt.IsPPC64() || (ctxt.IsARM64() && ctxt.IsDarwin())) && ctxt.IsExternal() return (ctxt.IsPPC64() || (ctxt.IsARM64() && ctxt.IsDarwin())) && ctxt.IsExternal()
} }
// On Wasm, we reserve 4096 bytes for zero page, then 4096 bytes for wasm_exec.js // On Wasm, we reserve 4096 bytes for zero page, then 8192 bytes for wasm_exec.js
// to store command line args. Data sections starts from at least address 8192. // to store command line args and environment variables.
// Data sections starts from at least address 12288.
// Keep in sync with wasm_exec.js. // Keep in sync with wasm_exec.js.
const wasmMinDataAddr = 4096 + 4096 const wasmMinDataAddr = 4096 + 8192
// address assigns virtual addresses to all segments and sections and // address assigns virtual addresses to all segments and sections and
// returns all segments in file order. // returns all segments in file order.