Skip to content

fix(compile): bump libsui to 0.16.3 to fix segfault under gVisor/Cloud Run - #35701

Merged
littledivy merged 1 commit into
denoland:mainfrom
littledivy:fix/compile-gvisor-at-phdr
Jul 2, 2026
Merged

fix(compile): bump libsui to 0.16.3 to fix segfault under gVisor/Cloud Run#35701
littledivy merged 1 commit into
denoland:mainfrom
littledivy:fix/compile-gvisor-at-phdr

Conversation

@littledivy

Copy link
Copy Markdown
Member

Fixes #35700.

Problem

A deno compile binary with a native npm addon crashes at startup on Google Cloud Run (debian:bookworm-slim, run directly as PID 1):

Inconsistency detected by ld.so: rtld.c: rtld_setup_main_map:
  Assertion `GL(dl_rtld_map).l_libname' failed!

(a plain Uncaught signal: 11 for the reduced repro). Invoking through the loader explicitly — CMD ["/lib64/ld-linux-x86-64.so.2", "/app/main"] — works.

Root cause

Cloud Run runs under gVisor. libsui's in-place Elf::append relocates the program header table into a new PT_LOAD past EOF, packed just above the highest existing vaddr — giving that segment a different file-offset→vaddr bias than the first PT_LOAD (~23 MB for the deno base). gVisor computes AT_PHDR = load_bias + (first_load.p_vaddr - first_load.p_offset) + e_phoff, so it lands tens of MB off the real table, reads garbage program headers, and dies before main. The Linux kernel recomputes AT_PHDR from the segment table, so it only breaks in the sandbox. The native addon is incidental — a trivial console.log binary reproduces it.

Fix

libsui 0.16.3 (denoland/sui#78) pins the relocated segment's vaddr to new_phoff + first_load_bias, preserving the first load's bias so the naive AT_PHDR computation is correct.

Verification

Reproduced under gVisor (runsc) on Linux x86_64:

  • the compiled @node-rs/bcrypt repro built with the current libsui crashes with the exact assertion; built with 0.16.3 it runs (gVisor exit=0).
  • also verified for PIE (+RELR), non-PIE, large .bss, and section-header-stripped inputs, and that it composes with the eu-strip fix (an eu-stripped binary also runs under gVisor).

The fix carries an AT_PHDR-invariant regression test in libsui.

…d Run

`deno compile` binaries crash at startup when run directly under gVisor
(Google Cloud Run): `rtld_setup_main_map: Assertion l_libname failed` (or a
plain SIGSEGV for stripped binaries). Running through the interpreter
explicitly (`ld-linux-x86-64.so.2 ./app`) works.

libsui relocated the program header table into a new PT_LOAD whose
file-offset-to-vaddr bias differed from the first PT_LOAD, so a loader that
computes `AT_PHDR = load_bias + first_load_bias + e_phoff` (gVisor) landed far
off the real table and read garbage program headers. libsui 0.16.3 pins the
new segment's vaddr to preserve that bias.

The native npm addon in the original report is incidental; a trivial program
reproduces it. Verified by reproducing under gVisor (runsc): the compiled
repro crashes before the bump and runs after.

Fixes denoland#35700
@littledivy
littledivy force-pushed the fix/compile-gvisor-at-phdr branch from 9f60a9e to 81ef6f9 Compare July 2, 2026 06:56
@littledivy
littledivy merged commit 3fa6cfa into denoland:main Jul 2, 2026
136 checks passed
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.

deno compile with native npm addon fails on Cloud Run in 2.9.x

1 participant