Skip to content

Commit 252324e

Browse files
neelanceRichard Musiol
authored and
Richard Musiol
committed
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 golang#49011 Change-Id: I48a6e952a97d33404ed692c98e9b49c5cd6b269b Reviewed-on: https://go-review.googlesource.com/c/go/+/358194 Trust: Richard Musiol <[email protected]> Run-TryBot: Richard Musiol <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 8c94aa4 commit 252324e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

misc/wasm/wasm_exec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@
519519

520520
// The linker guarantees global data starts from at least wasmMinDataAddr.
521521
// Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
522-
const wasmMinDataAddr = 4096 + 4096;
522+
const wasmMinDataAddr = 4096 + 8192;
523523
if (offset >= wasmMinDataAddr) {
524-
throw new Error("command line too long");
524+
throw new Error("total length of command line and environment variables exceeds limit");
525525
}
526526

527527
this._inst.exports.run(argc, argv);

src/cmd/link/internal/ld/data.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,10 +2442,11 @@ func splitTextSections(ctxt *Link) bool {
24422442
return (ctxt.IsPPC64() || (ctxt.IsARM64() && ctxt.IsDarwin())) && ctxt.IsExternal()
24432443
}
24442444

2445-
// On Wasm, we reserve 4096 bytes for zero page, then 4096 bytes for wasm_exec.js
2446-
// to store command line args. Data sections starts from at least address 8192.
2445+
// On Wasm, we reserve 4096 bytes for zero page, then 8192 bytes for wasm_exec.js
2446+
// to store command line args and environment variables.
2447+
// Data sections starts from at least address 12288.
24472448
// Keep in sync with wasm_exec.js.
2448-
const wasmMinDataAddr = 4096 + 4096
2449+
const wasmMinDataAddr = 4096 + 8192
24492450

24502451
// address assigns virtual addresses to all segments and sections and
24512452
// returns all segments in file order.

0 commit comments

Comments
 (0)