Skip to content

Add nodefaultstack build tag to unlink gVisor from lneto-only binaries - #5

Open
xinix00 wants to merge 1 commit into
usbarmory:mainfrom
xinix00:nodefaultstack
Open

Add nodefaultstack build tag to unlink gVisor from lneto-only binaries#5
xinix00 wants to merge 1 commit into
usbarmory:mainfrom
xinix00:nodefaultstack

Conversation

@xinix00

@xinix00 xinix00 commented Aug 10, 2026

Copy link
Copy Markdown

Interface.Init falls back to NewGVisorStack when no Stack is set; that single reference links the whole gVisor netstack into every binary using Interface, including ones that explicitly construct an LnetoStack. On a tamago/arm64 binary that is ~617KB of symbols plus their pclntab share.

This moves the fallback behind newDefaultStack and excludes gvisor.go under a new nodefaultstack build tag (excluding just the fallback still linked ~104KB of package-init graphs). Default builds are unchanged; with -tags nodefaultstack Init errors on a nil Stack and the linker drops gVisor entirely: 8.65MB → 6.83MB (−21%) on an otherwise identical binary.

Interface.Init falls back to NewGVisorStack when no Stack is set. That
unconditional reference links the entire gVisor netstack (~617KB of symbols
plus its pclntab share, ~1.8MB of a small tamago binary) into every binary
using Interface, including binaries that explicitly construct an LnetoStack
and never touch gVisor.

Move the fallback behind newDefaultStack and exclude gvisor.go under a new
'nodefaultstack' build tag. The whole file has to go rather than the fallback
alone: tagging only the function still linked ~104KB of package init graphs.

Default behavior is unchanged. Building with -tags nodefaultstack removes the
fallback, Init returns an error on a nil Stack, and the linker drops gVisor
entirely: measured 8.65MB -> 6.83MB (-21%) on an otherwise identical
tamago/arm64 binary, gVisor symbols 617KB -> 0.
@xinix00

xinix00 commented Aug 11, 2026

Copy link
Copy Markdown
Author

Trimmed the doc comments on both newDefaultStack halves and squashed; no functional change. Rebuilt and tested with and without the tag.

@soypat

soypat commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

If nodefaultstack is enabled it excludes gvisor build. A better approach may be to either:

  • rename nodefaultstack to be nogvisorstack so it is clearer in what the build tag actually does
  • add another file defaultstack_gvisor.go which is guarded by //go:build !nodefaultstack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants