Repository navigation
decompilers: add a manifold backend (whole-binary; CompCert pipeline in reverse) - #53
Conversation
Manifold (https://github.com/changliu98/manifold) is an open-source decompiler that runs CompCert's compilation pipeline in reverse: a binary is raised through Mach -> Linear -> RTL -> Cminor -> Csharpminor -> Clight and printed as C. It has no per-function entry point -- one process call decompiles a whole binary into a single translation unit -- so the backend shells out once per binary, splits the emitted unit into per-function definitions with a comment/string-aware scanner, and recovers each function's address from the FUN_<hex> names manifold gives functions in a stripped binary (falling back to the ELF symbol table when symbols survive). Each function's snippet carries the file-scope structs and globals it transitively references, so the per-function code decbench stores stands on its own. Addresses need no rebasing: manifold reports the ELF's own vaddrs, which is already the ELF-file space the metrics expect. Variables are left unset, so type_match scores manifold through the code-only parse_c_variables path (arguments by ABI position, locals by name), the same footing as the LLM backends. Point the backend at a build with MANIFOLD_BIN, or a `[manifold] binary = ...` entry in the decompilers config; it falls back to $PATH. Tests cover resolution, availability gating, the translation-unit splitter, and the address mapping through a fake manifold, so they run without the tool installed. The site content also gains the registry entry and the sample_set_only flag that the published v1 render already shows but that no source file carries, so re-rendering from content/ no longer drops them.
|
Hey @changliu98 would you be able to add a way to install your decompiler to one of the docker files? Since I will need to run this on my server and would love that part to be automated. |
Running the manifold backend previously meant building manifold by hand -- Rust, mold, libclang, libcapstone, a recursive clone, and a libz3 new enough for z3-sys -- and pointing MANIFOLD_BIN at the result. That is a lot to ask of a benchmark server, so `decbench decompiler-build manifold` now builds an image that is the entire install. docker/manifold.Dockerfile is a multi-stage build. The build stage clones manifold, initializes its Ascent submodule, and compiles it; the runtime stage carries out only the stripped binary and libz3, which is why the image is 247 MB rather than the multi-GB builder. Three things in it are not obvious: - Z3. The `z3` crate finds libz3 through pkg-config and Ubuntu's packaged 4.8 is too old for the z3-sys 0.11 bindings, so a pinned upstream release is unpacked to /opt/z3 with a hand-written z3.pc. Z3_DIST names the glibc the release was built for and has to match the base image, so bump it with Z3_VERSION. - Submodules are initialized by the paths .gitmodules maps rather than with a bare `--init --recursive`. manifold's tree used to carry a gitlink with no .gitmodules entry, which aborts that command; that is fixed upstream now, but deriving the paths keeps older MANIFOLD_REFs buildable. - The release profile is overridden to opt-level 3 + thin LTO through cargo's environment interface, leaving the manifold checkout untouched. manifold's own profile is tuned for build speed (opt-level 0), which is right for a working tree and wrong for an image built once and run over a corpus. Measured on a quiet host, decompilation is 1.7x faster on a 14 KB binary rising to 3.5x on 150 KB, for a 10m28s -> 28m36s build. Fat LTO was measured too and rejected: 0.99-1.06x, i.e. noise, for 49m and 25 GB of peak rustc RSS -- the crate is essentially one enormous ascent!-generated module, so whole-program merging has almost no cross-module inlining left to find. Every variant emits byte-identical C. ManifoldDecompiler picks native over Docker, the same order R2DecDecompiler uses: an executable from MANIFOLD_BIN / decompilers.toml / $PATH wins, so a developer can still benchmark a working tree without rebuilding an image, and the container is the fallback. Both paths write the same whole-program .c, so the splitter, the address recovery and the preamble collection are shared. build_image() gives the CLI's getattr hook something to find; MANIFOLD_IMAGE retags; MANIFOLD_THREADS reaches the container as RAYON_NUM_THREADS. The image records the revision it was built from at /opt/manifold.rev and get_version() reads it back, so a dockerized run reports the same git-<rev> a native one does even though MANIFOLD_REF tracks a branch. get_version() is memoized and the elapsed clock now stops before it is called: on the Docker path the probe is a container spawn, which was being charged to every binary's reported decompile time. Tests go 10 -> 19, still with neither manifold nor Docker installed -- a fake docker covers image inspect, build, and both run shapes. One of them, test_unavailable_without_binary, was quietly environment-dependent: it only neutralized MANIFOLD_BIN, so it passed by accident on machines that had never built the image and failed once one existed. It now neutralizes both paths. Verified end to end with no native manifold on the host: `decbench list-decompilers` reports manifold available at git-d9291ad, and a full `decbench run projects/sailr/bzip2.toml -O O0 -d manifold` completes clean -- 120 functions across two binaries, no failed_functions, all three metrics scored. Addresses were checked both ways, FUN_<hex> on a stripped binary and the ELF symbol table on bzip2's unstripped output.
|
@mahaloz done — decbench decompiler-build manifold
decbench run projects/sailr/<proj>.toml -O O0 -d manifoldNothing else on the host: it clones and builds manifold from source (Rust + a pinned Z3), Verified with Three things worth flagging for the server:
|
…s like it
Rebuilding to pick up new manifold commits silently did nothing. Docker keys the
`RUN git clone ... && git checkout $MANIFOLD_REF` layer on the command string,
and with MANIFOLD_REF defaulting to `master` that string never changes when the
branch moves. Measured against a manifold whose master had advanced one commit
past the image:
remote master : fb5b1bf
image holds : d9291ad
$ docker build -f docker/manifold.Dockerfile -t decbench/manifold:latest docker/
real 0m0.644s <- 29 cached layers
rebuilt image holds : d9291ad <- still the old revision
Nothing about that reports failure. get_version() keeps reading the revision the
image really has, so results are not mislabelled, but a maintainer who reruns
`decbench decompiler-build manifold` after an upstream fix scores the same code
as before and has no signal that they did.
build_image() now resolves MANIFOLD_REF to a commit SHA with `git ls-remote`
and passes that as the build arg. The clone layer's cache key is then the SHA,
so it is invalidated exactly when upstream moved and stays cached when it did
not -- the apt / Z3 / rustup layers above it survive either way, so a genuine
rebuild still skips ~5 minutes of setup and a no-op rebuild is still seconds.
A ref that is already a SHA passes through without touching the network.
When the ref cannot be resolved -- offline, no git, a ref that does not exist --
the build falls back to --no-cache and says so, because a slow honest build
beats a fast stale one.
A bare `docker build` still has the original trap, since there is nowhere to put
the resolution step; the Dockerfile header now says so and points at either
`--build-arg MANIFOLD_REF=<sha>` or --no-cache.
MANIFOLD_REPO is now forwarded as a build arg too, so pointing the image at a
fork no longer means editing the Dockerfile.
Three tests cover it: that a resolvable ref is pinned as a SHA and does not force
--no-cache, that an unresolvable one does, and that a SHA short-circuits without
needing git. 19 -> 22, still with neither manifold nor Docker installed.
Summary
Adds a raw backend for Manifold, an open-source decompiler that runs CompCert's compilation pipeline in reverse: a binary is raised through Mach → Linear → RTL → Cminor → Csharpminor → Clight and printed as C. Manifold's v1 numbers are already on the board from an external eval-kit submission; this PR is the harness, so a maintainer can run it on the full corpus instead of only scoring a submitted zip.
Per @mahaloz's request, installing manifold is now automated:
docker/manifold.Dockerfilebuilds it from source, and the backend falls back to that image when no native executable
resolves. A host needs Docker and nothing else. A native manifold still wins if one is
present (
MANIFOLD_BIN/decompilers.toml/$PATH), so a developer can benchmark aworking tree without rebuilding an image.
It is the first backend of a shape decbench hasn't had: whole-binary, no per-function entry point. One process call decompiles the entire binary into a single translation unit, so the per-function structure decbench needs is recovered from that unit rather than requested from the tool.
Backend design
manifold <binary> <out.c>subprocess per binary, underconfig.binary_timeout_seconds. A timeout or a missing output file becomes aDecompilationResultwithfailed_functions=["all"]andtimeout_occurredset, never an exception that takes down a run.;/}is the declarator; a braced group whose declarator ends in a parameter list is a function, whilestruct/union/enumdefinitions run on to their;. This is why the backend does not just regex forname(...) {.FUN_<hex>is manifold's name for an entry it has no symbol for, so the address is read straight out of the name; unstripped binaries fall back to.symtab/.dynsymvia pyelftools. Anything that resolves to neither is reported infailed_functionsrather than guessed at.type_matchscores it through theparse_c_variablestext path (arguments by ABI position, locals by name), the footing fix(type_match): credit arguments for code-only decompilers (fixes wcomment=0) #28 established for code-only backends.MANIFOLD_BINis an explicit override and wins outright (a bad value is a misconfiguration to report, not a reason to silently run some other build); otherwisebinaryfrom the decompilers config — per-version, then the tool's default section — then$PATH.MANIFOLD_LD_LIBRARY_PATHis merged into the child'sLD_LIBRARY_PATH(manifold links libz3 dynamically), andMANIFOLD_THREADScaps its rayon pool so a parallel driver can keep N binaries from each grabbing every core.get_version()reportsgit-<short rev>of the checkout the executable sits in, since manifold has no--version.Docker image (
docker/manifold.Dockerfile)Multi-stage: the build stage clones manifold, initializes its Ascent submodule and compiles
it; the runtime stage carries out only the stripped binary and libz3, so the image is 247 MB
rather than the multi-GB builder. Selection order mirrors
R2DecDecompiler._select_path:native > this image.
Three things worth knowing before you bump it:
z3crate finds libz3 through pkg-config, and Ubuntu's packaged 4.8 is too oldfor the
z3-sys0.11 bindings, so a pinned upstream release is unpacked to/opt/z3with ahand-written
z3.pc.Z3_DISTnames the glibc the release was built for and must match thebase image, so bump it together with
Z3_VERSION.MANIFOLD_REFdefaults tomaster; pass a SHA or tag to freeze a run. The image recordswhat it actually built at
/opt/manifold.revandget_version()reads it back, so resultsalways name the exact revision even though the ref floats.
decompiler-build, not a baredocker build. Docker keys thegit clonelayer on the command string, which does not change when a branch moves — so a plain rebuild
after manifold gains commits reuses the cached clone and silently ships the same revision,
in about a second, reporting no error.
build_image()resolvesMANIFOLD_REFto a SHA viagit ls-remoteand passes that as the build arg, so the clone layer is invalidated exactlywhen upstream moved and stays cached when it did not (the apt/Z3/rustup layers survive
either way). If the ref cannot be resolved — offline, no
git, bad ref — it falls back to--no-cacheand says so. By hand, pass--build-arg MANIFOLD_REF=<sha>or--no-cache.rustcRSS, because manifold is one enormousascent!-generated module. Worth checking your build host has the headroom.The release profile is overridden to
opt-level 3+ thin LTO via cargo's environmentinterface, leaving the manifold checkout untouched — manifold's own profile is tuned for build
speed (
opt-level 0), which is right for a working tree and wrong for an image built once andrun over a corpus. Measured on a quiet host, same revision both sides:
cat)ls)du)Build cost is 10m28s → 28m36s, paid once. Fat LTO was measured and rejected: 0.99–1.06x
(noise) for 49m and 25.2 GB peak RSS — one giant generated module leaves whole-program merging
almost no cross-module inlining to find. It stays reachable via
--build-arg CARGO_PROFILE_RELEASE_LTO=fat. Every variant emits byte-identical C.Site content
site/data/aggregates.jsononmainalready renders Manifold with a display name, URL, logo, andsample_set_only, but no source file carries any of it — 24cc9a6 published the built tree only, so a re-render fromcontent/would drop the registry entry and start showing Manifold's sample-set row on the full-corpus presets. This PR adds the matchingdecompilers.tomlentry (includinglogo = true, whose.dlogo-manifoldCSS you already landed in 24cc9a6) and appendsmanifoldtosample_set_onlyinsite.toml. Happy to drop that second hunk if you'd rather keep it a local edit — and it should come out once a full-corpus run covers manifold.Verification
pytest tests/test_manifold_backend.py: 22 passed (was 10). The new ones covernative-over-Docker selection, availability gating on the image alone, the
docker runmountlayout,
MANIFOLD_THREADS→RAYON_NUM_THREADS,MANIFOLD_IMAGEretagging, thebuild_image()hook, and version memoization — all through a fakedocker, so they runwith neither manifold nor Docker installed. One pre-existing test was quietly
environment-dependent (it only neutralized
MANIFOLD_BIN, so it passed by accident on hoststhat had never built the image, and failed once one existed); it now neutralizes both paths.
Three more cover the rebuild-staleness fix: a resolvable ref is pinned as a SHA without
forcing
--no-cache, an unresolvable one forces it, and a ref that is already a SHAshort-circuits without needing
git.test_content.pyrendering assertions, identical on clean
mainin a separate worktree.ruffandblack --checkclean on all touched files;mypy --follow-imports=skip decbench/decompilers/raw/manifold_raw.pyclean. (Repo-wideruff check decbench/reports 21pre-existing findings on
main; none are in files this PR touches.)MANIFOLD_BINdeliberately pointed at anonexistent path, so the run is forced through the image):
decbench list-decompilers→manifold | Y | git-d9291addecbench run projects/sailr/bzip2.toml -O O0 -d manifold→ completes clean; 120functions across 2 binaries,
failed_functionsempty on both, all three metrics scored(GED 50.8%, byte_match 3.3%, type_match 7.4%).
FUN_<hex>on a stripped binary (add_two 0x401136,classify 0x40113e,main 0x401153, matchingnmon the unstripped twin) and the ELFsymbol table on bzip2's unstripped output.
Maintainer notes
decbench decompiler-build manifold— no Rust, mold, libclang or z3 on the host. Building it natively still needs all of those plus a--recursiveclone, andMANIFOLD_LD_LIBRARY_PATH=<z3>/libif z3 is not on the default loader path; that path is now optional.binary_timeout_secondsis the knob that matters, not a per-function budget, and a large binary can run long. On the 224-binary eval kit, 12 concurrent jobs × 10 threads each was a good balance on a 128-core box.docs/agents.mdsays agents must not edit it, so this PR doesn't. Suggested entry under### 2026-07-27:reeval_*+finalize_results.pypass on your side.🤖 Generated with Claude Code
https://claude.ai/code/session_01JquMXzqYHQTS62SnP98Pg1