From 9d4a78427803535df0b589e48107a9f3b7973f1d Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 16 Apr 2026 13:29:10 -0700 Subject: [PATCH 1/4] runtime: handle GODEBUG on wasip2 --- GNUmakefile | 2 +- src/runtime/env.go | 2 +- src/runtime/env_wasip2.go | 18 ++++++++++++++++++ src/syscall/env_wasip2.go | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/runtime/env_wasip2.go diff --git a/GNUmakefile b/GNUmakefile index eadcf13d04..167e8b79a6 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -488,7 +488,7 @@ TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_WINDOWS) TEST_IOFS := false endif -TEST_SKIP_FLAG := -skip='TestExtraMethods|TestParseAndBytesRoundTrip/P256/Generic|TestParseQueryLimits|TestParseStrictIpv6|TestAsValidation' +TEST_SKIP_FLAG := -skip='TestExtraMethods|TestParseAndBytesRoundTrip/P256/Generic|TestAsValidation' TEST_ADDITIONAL_FLAGS ?= # Test known-working standard library packages. diff --git a/src/runtime/env.go b/src/runtime/env.go index 676c634d99..899321c266 100644 --- a/src/runtime/env.go +++ b/src/runtime/env.go @@ -1,4 +1,4 @@ -//go:build linux || darwin || windows || wasip1 +//go:build (linux || darwin || windows || wasip1) && !wasip2 package runtime diff --git a/src/runtime/env_wasip2.go b/src/runtime/env_wasip2.go new file mode 100644 index 0000000000..7beb8695c5 --- /dev/null +++ b/src/runtime/env_wasip2.go @@ -0,0 +1,18 @@ +//go:build wasip2 + +package runtime + +// Notify the runtime when environment variables change. +// On wasip2, the environment is managed in Go (no C setenv), but +// internal/godebug still needs to be notified of GODEBUG changes. + +//go:linkname syscallSetenv syscall.runtimeSetenv +func syscallSetenv(key, value string) { + if key == "GODEBUG" && godebugUpdate != nil { + godebugUpdate(key, value) + } +} + +//go:linkname syscallUnsetenv syscall.runtimeUnsetenv +func syscallUnsetenv(key string) { +} diff --git a/src/syscall/env_wasip2.go b/src/syscall/env_wasip2.go index 8064d0d281..f9468936bb 100644 --- a/src/syscall/env_wasip2.go +++ b/src/syscall/env_wasip2.go @@ -43,11 +43,13 @@ func Setenv(key, val string) (err error) { } } libc_envs[key] = val + runtimeSetenv(key, val) return nil } func Unsetenv(key string) (err error) { delete(libc_envs, key) + runtimeUnsetenv(key) return nil } From 2b9290b384bb1a629a99145fcb6168ffed9f7355 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sat, 18 Apr 2026 12:13:40 -0700 Subject: [PATCH 2/4] Support env on more platforms to get GODEBUG working --- src/runtime/env_nonhosted.go | 43 ++++++++++++++++++++++++++++++++ src/syscall/env_nonhosted.go | 32 +++++++++++++++++++----- src/syscall/syscall_nonhosted.go | 4 +++ 3 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 src/runtime/env_nonhosted.go diff --git a/src/runtime/env_nonhosted.go b/src/runtime/env_nonhosted.go new file mode 100644 index 0000000000..e3bef9dbcc --- /dev/null +++ b/src/runtime/env_nonhosted.go @@ -0,0 +1,43 @@ +//go:build baremetal || js || wasm_unknown + +package runtime + +//go:linkname syscallSetenv syscall.runtimeSetenv +func syscallSetenv(key, value string) { + entry := key + "=" + value + for i, e := range env { + if envKey(e) == key { + env[i] = entry + if key == "GODEBUG" && godebugUpdate != nil { + godebugUpdate(key, value) + } + return + } + } + env = append(env, entry) + if key == "GODEBUG" && godebugUpdate != nil { + godebugUpdate(key, value) + } +} + +//go:linkname syscallUnsetenv syscall.runtimeUnsetenv +func syscallUnsetenv(key string) { + for i, e := range env { + if envKey(e) == key { + env = append(env[:i], env[i+1:]...) + if key == "GODEBUG" && godebugUpdate != nil { + godebugUpdate(key, "") + } + return + } + } +} + +func envKey(entry string) string { + for i := 0; i < len(entry); i++ { + if entry[i] == '=' { + return entry[:i] + } + } + return entry +} diff --git a/src/syscall/env_nonhosted.go b/src/syscall/env_nonhosted.go index 446ba55d2d..98f198743b 100644 --- a/src/syscall/env_nonhosted.go +++ b/src/syscall/env_nonhosted.go @@ -28,18 +28,38 @@ func Getenv(key string) (value string, found bool) { } func Setenv(key, val string) (err error) { - // stub for now - return ENOSYS + if len(key) == 0 { + return EINVAL + } + for i := 0; i < len(key); i++ { + if key[i] == '=' || key[i] == 0 { + return EINVAL + } + } + for i := 0; i < len(val); i++ { + if val[i] == 0 { + return EINVAL + } + } + runtimeSetenv(key, val) + return nil } func Unsetenv(key string) (err error) { - // stub for now - return ENOSYS + runtimeUnsetenv(key) + return nil } func Clearenv() (err error) { - // stub for now - return ENOSYS + for _, s := range Environ() { + for j := 0; j < len(s); j++ { + if s[j] == '=' { + Unsetenv(s[:j]) + break + } + } + } + return nil } func runtime_envs() []string diff --git a/src/syscall/syscall_nonhosted.go b/src/syscall/syscall_nonhosted.go index a0965692f4..82633a99f4 100644 --- a/src/syscall/syscall_nonhosted.go +++ b/src/syscall/syscall_nonhosted.go @@ -176,3 +176,7 @@ type RawSockaddrInet4 struct { type RawSockaddrInet6 struct { // stub } + +// These two functions are provided by the runtime. +func runtimeSetenv(key, value string) +func runtimeUnsetenv(key string) From f8808dec5e6ca937107108968d88327a835a736c Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sat, 18 Apr 2026 12:18:00 -0700 Subject: [PATCH 3/4] Forgot some code --- src/runtime/env_wasip2.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/env_wasip2.go b/src/runtime/env_wasip2.go index 7beb8695c5..ffc18d9253 100644 --- a/src/runtime/env_wasip2.go +++ b/src/runtime/env_wasip2.go @@ -15,4 +15,7 @@ func syscallSetenv(key, value string) { //go:linkname syscallUnsetenv syscall.runtimeUnsetenv func syscallUnsetenv(key string) { + if key == "GODEBUG" && godebugUpdate != nil { + godebugUpdate(key, "") + } } From b65b29b608a6af8423faa3189ef73df5c0672620 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sat, 18 Apr 2026 12:28:43 -0700 Subject: [PATCH 4/4] Exclude even more --- src/runtime/env.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/env.go b/src/runtime/env.go index 899321c266..f20cc0851d 100644 --- a/src/runtime/env.go +++ b/src/runtime/env.go @@ -1,4 +1,4 @@ -//go:build (linux || darwin || windows || wasip1) && !wasip2 +//go:build (linux || darwin || windows || wasip1) && !wasip2 && !baremetal && !wasm_unknown package runtime