Skip to content

release: 0.4.13 — fix(elfpatch): patchelf op order workaround - #257

Merged
Sunrisepeak merged 7 commits into
mainfrom
release/0.4.13-elfpatch-order-fix
May 2, 2026
Merged

Sunrisepeak merged 7 commits into
mainfrom
release/0.4.13-elfpatch-order-fix

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Summary

Hotfix for a patchelf 0.18.0 corruption bug that just went production-wide after xim-pkgindex#108 declared `runtime = { glibc, gcc }` deps on cmake / mdbook / ninja / node / xmake. The predicate-driven elfpatch then fires on these binaries; for compact ELFs (~≤ 280 KB, e.g. ninja 1.12.1 at 273 KB) patchelf 0.18.0 has an order-sensitive corruption bug.

`mcpplibs-xpkg v0.0.37` reverses the op order so `--set-rpath` runs before `--set-interpreter`. This PR bumps to 0.0.37 + version 0.4.13.

Repro on 0.4.12 (current state of `main`)

```sh
$ xlings install ninja
$ ninja --version
Segmentation fault (core dumped) # SEGV @ 0x8 right after execve
```

```sh

OR via cmake driving small subprocesses:

$ ... → cmake failed(-1) # child killed by signal
```

Evidence: libxpkg `main` CI was green at 18:23 UTC, then went red after I rerun it at 21:00 UTC — without any libxpkg code change. Only xim-pkgindex#108 changed in between. Same chicken-and-egg as 0.4.12 hotfix.

After fix (verified locally)

```
elfpatch._apply: source=predicate:single
ninja: elfpatch auto: 1 1 0
$ ninja --version
1.12.1 ← exit 0

INTERP=…/xim-x-glibc/2.39/lib64/ld-linux-x86-64.so.2 ← rewrites correctly
RUNPATH=…/glibc/lib64:…/gcc/lib64:…/subos/default/lib ← closure correct
```

Migration / known limitation

0.4.12 → 0.4.13 is binary-compatible (in-place self-update via `xlings self install` / quick_install).

Already-broken payloads (e.g. ninja installed under 0.4.12 after #108 deps were declared) need a manual `xlings uninstall && xlings install ` cycle — the new `apply_elfpatch_auto` won't rerun on a "non-empty install_dir" (intentional, see installer.cppm `payloadInstalled` gate). For automatic re-patch, a future `xlings doctor --fix-elfpatch` could detect + heal corrupted payloads.

Test plan

  • libxpkg unit tests 27/27 pass (post-fix, new `ApplyElfpatchAuto_LinuxRpathBeforeInterpreter` regression test)
  • E2E in isolated `XLINGS_HOME`: `xlings install ninja` from scratch with v0.4.13 binary + v0.0.37 libxpkg
    • elfpatch `source=predicate:single` triggers
    • ninja file size 273 KB → 290 KB (patched correctly)
    • INTERP rewrites to xim-x-glibc loader
    • RUNPATH = correct closure
    • `ninja --version` exits 0
  • CI: pinned BOOTSTRAP_XLINGS_VERSION 0.4.8 should pass cleanly (same as PR release: 0.4.12 — fix(elfpatch): self-patch opt-in + cross-platform polish #255)

Related

Bumps VERSION 0.4.12 → 0.4.13 + add_requires("mcpplibs-xpkg 0.0.37").

Hotfix for a patchelf 0.18.0 corruption bug that surfaced production-
wide after xim-pkgindex#108 declared `runtime = { glibc, gcc }` deps
on five common prebuilt packages (cmake, mdbook, ninja, node, xmake).
Predicate-driven elfpatch then fired on these binaries; for compact
ELFs (~≤ 280 KB, e.g. ninja 1.12.1 at 273 KB) patchelf 0.18.0 has an
order-sensitive corruption bug: --set-interpreter before --set-rpath
shifts the dynamic section so the subsequent rpath op writes through
DT_NEEDED, segfaulting the binary at execve+1 with no recovery.

mcpplibs-xpkg v0.0.37 reverses the op order in
_patch_elf_executables and _patch_elf fallback so --set-rpath runs
first. Linux-only fix; macOS / Windows unaffected (different
toolchains, no equivalent issue).

Symptom on 0.4.12:
    $ xlings install ninja
    $ ninja --version
    Segmentation fault (core dumped)
    # OR
    $ cmake ...                    # cmake driving small build tools
    failed(-1) — child process killed by signal

Symptom on 0.4.13 (verified locally with isolated XLINGS_HOME):
    $ xlings install ninja
    elfpatch._apply: source=predicate:single
    ninja: elfpatch auto: 1 1 0
    $ ninja --version
    1.12.1
    INTERP=…/xim-x-glibc/2.39/lib64/ld-linux-x86-64.so.2
    RUNPATH=…/xim-x-glibc/lib64:…/xim-x-gcc/lib64:…/subos/default/lib

Migration: 0.4.12 → 0.4.13 is binary-compatible. The in-place
self-update path (xself install / quick_install) handles the upgrade.
After upgrade, packages affected by xim-pkgindex#108 (cmake / mdbook /
ninja / node / xmake) need a re-install via `xlings uninstall <pkg> &&
xlings install <pkg>` to rebuild the corrupted payload — `xlings
install` alone won't re-patch already-installed payloads (correct
"installed payload is sacred" behavior, see installer.cppm:1080).
For the auto-recovery path (broken payload silently re-patched on
next install), see TODO in upstream tracking.

Verified locally:
  - libxpkg unit tests 27/27 pass (post-fix, includes new
    ApplyElfpatchAuto_LinuxRpathBeforeInterpreter regression test)
  - E2E in isolated XLINGS_HOME: ninja install with new predicate +
    new order produces a working binary, INTERP / RUNPATH correctly
    set, `ninja --version` exits 0

libxpkg PR: openxlings/libxpkg#13 (merged, v0.0.37)
Analysis: docs/plans/2026-05-03-patchelf-order-bug-analysis.md (in libxpkg)
mcpplibs-index: mcpplibs/mcpplibs-index@bc4f740 registers v0.0.37
The xlings E2E test fixture is dynamically cloned from xim-pkgindex
main at CI time. xim-pkgindex#108 (declare runtime deps on
cmake/mdbook/ninja/node/xmake) introduced bare-name deps that cascade
into ambiguity errors in E2E-05's dual-mount scenario, plus exposed
latent issues (gcc-specs-config not auto-activated, node not finding
libstdc++ at runtime).

Pin XIM_PKGINDEX_REF to commit 9cb6982 (PR #106 merge — last commit
before #108) until those cascading issues stabilize. This restores the
previously-passing E2E green state and decouples xlings's release CI
from in-flight xim-pkgindex churn.

Bump after xim-pkgindex deps stabilize: namespace prefixes universal
(continuation of #110/#111), runtime lib closure verified (gcc's
lib64 actually reaches consumers' RPATH), and gcc-specs-config
activation pathway sorted out.

Applied to all four workflows that clone the fixture: xlings-ci-linux,
xlings-ci-macos, xlings-ci-windows, release.
`git clone --branch` only accepts branch/tag names, not SHAs. When
XIM_PKGINDEX_REF is set to a commit SHA (40-char hex), do a full clone
then `git checkout <sha>`. Branch/tag refs continue to use the depth-1
shallow clone path.
Bind XIM_PKGINDEX_REF time-matched with BOOTSTRAP_XLINGS_VERSION=v0.4.8
(xlings released 2026-04-30 18:25 UTC, this commit lands 2026-04-30
17:43 UTC — last xim-pkgindex commit before 0.4.8 went live, so the
schema/conventions match what 0.4.8 expects).

Decouples xlings CI from in-flight xim-pkgindex churn (post #107: bare-
name deps + new runtime-dep declarations on prebuilts cascading into
E2E-05's dual-mount scenario). Bump in lockstep with BOOTSTRAP_XLINGS
once both stabilize.

Applied to all four workflows that clone the fixture: xlings-ci-linux,
xlings-ci-macos, xlings-ci-windows, release.
@Sunrisepeak
Sunrisepeak merged commit 9471d98 into main May 2, 2026
3 checks passed
Sunrisepeak added a commit that referenced this pull request May 2, 2026
CI 4th attempt with main HEAD (3f1462d) failed: post-#108 pkgindex
schema needs hooks that v0.4.13 doesn't yet wire up:
  - gcc-specs-config (added in #109) doesn't auto-activate; gcc's
    config hook fails 'no version set for gcc-specs-config'
  - node has runtime dep on xim:gcc but its rpath closure misses
    gcc's libstdc++ subdir → libstdc++.so.6 not found

These need fixes in either xlings (resolver/config hook ordering)
or xim-pkgindex (gcc-specs-config registration / lib paths) — both
out of scope for this CI bump.

Pin XIM_PKGINDEX_REF back to 83044b5 (verified known-good for v0.4.13
during PR #257 release CI). Future bump: in lockstep with the next
xlings release that supports post-#108 schema.
Sunrisepeak added a commit that referenced this pull request May 2, 2026
* ci: bump bootstrap xlings v0.4.8 → v0.4.13 + xim-pkgindex pin

Co-bump BOOTSTRAP_XLINGS_VERSION and XIM_PKGINDEX_REF across all four
workflows that clone the fixture (xlings-ci-linux, xlings-ci-macos,
xlings-ci-windows, release).

  BOOTSTRAP_XLINGS_VERSION: v0.4.8 → v0.4.13
  XIM_PKGINDEX_REF: 83044b5 (pre-#108) → 3f1462d (xim-pkgindex main
                                          tip as of v0.4.13)

Why co-bump: the bootstrap xlings's resolver / elfpatch / catalog
behavior must match the pkgindex schema (legacy deps array vs new
runtime/build split, namespace conventions, exports.runtime.loader,
etc.). Bumping one without the other risks an in-flight pkgindex
breaking a stable bootstrap or vice versa — exactly what happened
during the 0.4.13 hotfix sequence (xim-pkgindex#108 added bare-name
deps that 0.4.8's resolver couldn't disambiguate, cascading through
E2E-05 dual-mount).

v0.4.13 contains the elfpatch op-order fix (libxpkg PR #13 / v0.0.37)
and pairs with xim-pkgindex 3f1462d (PRs #110/#111 namespace fixes
applied). Both refs verified together via PR #257's CI.

The earlier fixture-pin comment is reframed: it's not a one-off
workaround but a permanent bump-in-lockstep policy.

* ci: revert XIM_PKGINDEX_REF to 83044b5 (last known-good vs v0.4.13)

CI 4th attempt with main HEAD (3f1462d) failed: post-#108 pkgindex
schema needs hooks that v0.4.13 doesn't yet wire up:
  - gcc-specs-config (added in #109) doesn't auto-activate; gcc's
    config hook fails 'no version set for gcc-specs-config'
  - node has runtime dep on xim:gcc but its rpath closure misses
    gcc's libstdc++ subdir → libstdc++.so.6 not found

These need fixes in either xlings (resolver/config hook ordering)
or xim-pkgindex (gcc-specs-config registration / lib paths) — both
out of scope for this CI bump.

Pin XIM_PKGINDEX_REF back to 83044b5 (verified known-good for v0.4.13
during PR #257 release CI). Future bump: in lockstep with the next
xlings release that supports post-#108 schema.
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