From 900443349b17bb1f989daa64856546955c70d104 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Sun, 24 Oct 2021 12:28:18 +0200 Subject: [release-branch.go1.16] 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. Updates #49011. Fixes #49153. Change-Id: I48a6e952a97d33404ed692c98e9b49c5cd6b269b Reviewed-on: https://go-review.googlesource.com/c/go/+/358194 Trust: Richard Musiol Run-TryBot: Richard Musiol TryBot-Result: Go Bot Reviewed-by: Cherry Mui (cherry picked from commit 252324e879e32f948d885f787decf8af06f82be9) Reviewed-on: https://go-review.googlesource.com/c/go/+/359400 Trust: Dmitri Shuralyov Run-TryBot: Dmitri Shuralyov --- misc/wasm/wasm_exec.js | 4 ++-- src/cmd/link/internal/ld/data.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js index a0a264278b..48164c3a4b 100644 --- a/misc/wasm/wasm_exec.js +++ b/misc/wasm/wasm_exec.js @@ -566,9 +566,9 @@ // The linker guarantees global data starts from at least wasmMinDataAddr. // Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr. - const wasmMinDataAddr = 4096 + 4096; + const wasmMinDataAddr = 4096 + 8192; 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); diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 54a1d188cd..7028b85cac 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -2330,10 +2330,11 @@ func assignAddress(ctxt *Link, sect *sym.Section, n int, s loader.Sym, va uint64 return sect, n, va } -// On Wasm, we reserve 4096 bytes for zero page, then 4096 bytes for wasm_exec.js -// to store command line args. Data sections starts from at least address 8192. +// On Wasm, we reserve 4096 bytes for zero page, then 8192 bytes for wasm_exec.js +// to store command line args and environment variables. +// Data sections starts from at least address 12288. // 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 // returns all segments in file order. -- cgit v1.2.3-54-g00ecf