Skip to content

fix(build): force true static linking for guest binary#414

Open
DorianZheng wants to merge 1 commit intomainfrom
fix/static-linking-guest-binary
Open

fix(build): force true static linking for guest binary#414
DorianZheng wants to merge 1 commit intomainfrom
fix/static-linking-guest-binary

Conversation

@DorianZheng
Copy link
Copy Markdown
Member

Summary

  • Fix guest binary being built as static-PIE (ET_DYN) instead of true static (ET_EXEC), which fails silently inside the VM
  • Strengthen static linking checks in build scripts to catch static-PIE
  • Improve setup-manylinux.sh for Amazon Linux 2023 compatibility

Root Cause

libkrunfw's kernel has CONFIG_RANDOMIZE_BASE disabled. Without ASLR, the kernel's ELF loader can't properly handle static-PIE (ET_DYN) executables — the guest exits immediately with vCPU exit code 0 and empty console output.

The root .cargo/config.toml was missing -C link-arg=-static and linker specification. Without -static, musl-gcc produces static-PIE which passed the old build check (grepped for "dynamically linked") but crashed in the VM.

Changes

File Change
.cargo/config.toml Add linker + -C link-arg=-static (root cause fix)
build-guest.sh Check "statically linked" instead of rejecting "dynamically linked"
build-shim.sh Add static linking verification on Linux
build-runtime.sh Add final gate: verify both binaries before packaging
setup-manylinux.sh sudo support, curl-minimal conflict, optional GPU pkgs, patchelf
setup-musllinux.sh Add patchelf

Test plan

  • EC2 make guest with fixed config → statically linked (ET_EXEC)
  • EC2 make guest with original config → caught by strengthened check
  • Original PIE binary: runs on host (ASLR enabled), segfaults/fails in VM (no ASLR)
  • CI log analysis confirms v0.7.5 shipped static-PIE (ELF shared object, static-pie linked)
  • Full e2e test with maturin develop rebuild (requires EC2 with all deps)
  • CI green on all platforms

…-PIE

The v0.7.5 guest binary was built as static-PIE (ET_DYN) instead of true
static (ET_EXEC). Static-PIE binaries fail silently inside the VM because
libkrunfw's kernel has CONFIG_RANDOMIZE_BASE disabled — the ELF loader
can't handle ET_DYN without ASLR, causing the guest to exit immediately
with vCPU exit code 0 and empty console output.

Root cause: .cargo/config.toml was missing `-C link-arg=-static` and
`linker` specification. Without `-static`, musl-gcc produces static-PIE
which passed the old build check (grepped for "dynamically linked") but
crashed in the VM.

Changes:
- .cargo/config.toml: add linker + `-C link-arg=-static` (syncs with
  guest/.cargo/config.toml)
- build-guest.sh: check for "statically linked" instead of rejecting
  "dynamically linked" — catches static-PIE
- build-shim.sh: add static linking verification on Linux
- build-runtime.sh: add final gate check before packaging
- setup-manylinux.sh: add sudo support, handle package conflicts
  (curl-minimal), optional GPU packages, add patchelf
- setup-musllinux.sh: add patchelf
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.

1 participant