Fix musl loader (libc.so) segfault on old guest kernels#8
Merged
Conversation
…old kernels mk-arch-bundle ran 'patchelf --set-rpath /igloo/dylibs' on every staged ELF, including libc.so (the musl loader, aliased ld-musl-<arch>.so.1). musl libc ships with no rpath, so patchelf had to grow .dynamic/.dynstr and appended a fresh PT_LOAD segment. The loader is the PT_INTERP the kernel maps for every dynamic guest binary, and older guest kernels (e.g. Linux 4.10) mishandle that extra RW segment: they never map the loader's BSS, so the first write in musl's __dls2 (storing the 'ldso' global) faults and every dynamic binary segfaults at startup. The loader needs no rpath of its own (NEEDED libs resolve via each program's RUNPATH=/igloo/dylibs), so leave libc.so's stock single-RW-LOAD layout untouched. Other dylibs/tools already had /nix/store rpaths that patchelf rewrites in place, so they are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Dynamic guest binaries built/staged by penguin-tools (the drop-in compiler's output, gdbserver, strace, python3, …) segfault at startup on older guest kernels (e.g. Linux 4.10), while working fine on 6.13. This blocks penguin's
basic_targeton every arch that exercises a 4.10 kernel and would break the tools on any 4.10-based rehost.Root cause
A core dump of a crashing drop-in faults inside musl's
__dls2at themov %rdi, ldso(%rip)store — writing the loader'sldsoglobal, which lives in the BSS of libc.so's first RW LOAD segment.mk-arch-bundlerunspatchelf --set-rpath /igloo/dylibson every staged ELF, including libc.so (the musl loader, aliasedld-musl-<arch>.so.1). Stock musl libc has no rpath, so patchelf must grow.dynamic/.dynstrand appends a fresh PT_LOAD, leaving libc.so with two RW LOAD segments. libc.so is thePT_INTERPthe kernel maps for every dynamic binary; older kernels mishandle that extra RW segment and never map the loader's BSS → the firstldsowrite faults → every dynamic binary segfaults.Stock musl libc.so has a single RW LOAD and no rpath on all arches; only libc.so was mangled (other dylibs/tools already carried
/nix/storerpaths that patchelf rewrites in place).Fix
Skip
patchelf --set-rpathonlibc.so. The loader needs no rpath — NEEDED libs resolve via each program's ownRUNPATH=/igloo/dylibs— so its stock, single-RW-LOAD layout is preserved and old kernels can map it.Verified: stock cross-musl
libc.soisLOADs / RW=1 / rpath=''on every arch; the appended segment came solely from the patchelf rpath edit.