Repository navigation
tests: add property test for binary-preserving rewrites - #651
Merged
Merged
Conversation
Mic92
force-pushed
the
property-testing
branch
9 times, most recently
from
June 25, 2026 12:50
4a3e1df to
0313317
Compare
Mic92
enabled auto-merge
June 25, 2026 15:32
Mic92
disabled auto-merge
June 25, 2026 15:32
PR #645 fixed --remove-rpath but --remove-needed has the same in-place compaction and the same bug: DT_MIPS_RLD_MAP_REL stores the offset to .rld_map relative to its own .dynamic slot, so when the slot moves the value must be adjusted, and rewriteSections() does not run because no section was replaced. Factor the shared compact-and-adjust loop into compactDynamic() and use it from both callers. The regression test recomputes the loader's invariant from readelf output, so it does not need to execute the binary and runs on any host with a MIPS toolchain.
Relocated sections are written into the reserved area at the start of the file and inherit the permissions of the LOAD segment already covering it. For a non-PIE executable that fits the relocation without growing the file (e.g. linked with a large max-page-size), a writable section such as .dynamic ends up read-only and the loader segfaults writing DT_DEBUG. Make that segment writable. If it is executable, prefer to grow the file so shiftFile splits the reserved area into its own R/W segment and avoids W+X; fall back to marking the segment writable only when there is no room below the load address to add pages. Found by tests/property-rewrite.sh.
The existing fuzz harness feeds mostly-invalid bytes looking for crashes. This adds the complementary property: applying patchelf operations to a valid, runnable binary must leave it runnable. It builds dynamic executables with randomized layout/link options (page size, separate-code, relro, hash style, build-id, PIE), applies a random sequence of rpath/needed/interpreter/replace-needed operations, and runs the binary after each one. Dependencies are resolved via LD_LIBRARY_PATH so rpath edits exercise the section rewrite without changing whether libs are findable, and each case verifies the freshly built binary runs before patching so a build hiccup is skipped rather than reported as a regression.
Add a Debian/glibc job for mips64le, which has no musl/Alpine image. It is test-only (no release artifact) and runs the suite under QEMU, exercising patchelf's MIPS-specific paths (DT_MIPS_RLD_MAP_REL, .MIPS.options, etc.). The property test uses a reduced ITERS there since QEMU emulation is slow.
The nix jobs (hydraJobs.release, tarball, win32/win64 cross) rebuild from scratch on every run. hestia turns the GitHub Actions cache into a Nix binary cache with no extra accounts or secrets, so later runs substitute what earlier runs built. The full closure is cached (no upstream filter): the org's Enterprise plan is not bound by the public 10 GB quota, and a local mirror of the nixpkgs paths is faster than round-tripping to cache.nixos.org. A daily GC workflow keeps the default-branch scope from growing without bound; PR-scoped caches die with their branch already.
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.
The existing fuzz harness feeds mostly-invalid bytes looking for crashes. This adds the complementary property: applying patchelf operations to a valid, runnable binary must leave it runnable.
It builds dynamic executables with randomized layout/link options (page size, separate-code, relro, hash style, build-id, PIE), applies a random sequence of rpath/needed/interpreter/replace-needed operations, and runs the binary after each one. Dependencies are resolved via LD_LIBRARY_PATH so rpath edits exercise the section rewrite without changing whether libs are findable, and each case verifies the freshly built binary runs before patching so a build hiccup is skipped rather than reported as a regression.