c-mimir-dump
Capture C and C++ compiler invocations and read their LLVM bitcode into Mímir's shared Arrow tables. The compiler and reader require LLVM 23.1.5. Source capture does not prove whole-program link membership or perform reach analysis.
Build and image
Run builds and tests inside the pinned container, with at most eight CPUs and 64 GiB of memory, and nice -n 10. The recipe is crates/c-mimir-dump/container/Containerfile. Its context is the directory containing the nornir checkout. It pins the Rust base image, Debian snapshot, and the LLVM release archive's SHA-256. This recipe targets Linux x86_64. The image contains the kernel build prerequisites, CMake/Ninja, Rust, clang, lld and the wrapper symlinks.
The Rust binary links libcontainer directly. The run subcommand does not call podman, youki, crun or runc executables. Image provisioning remains external: build the recipe using the image provisioner, record the resulting image manifest digest, and extract its root filesystem. Verify that digest before passing the rootfs to run; --image-digest records the supplied identity and does not itself verify the extracted filesystem.
For a container test environment with the source at /work/nornir and LLVM at /opt/llvm:
export MIMIR_LLVM_CONFIG=/opt/llvm/bin/llvm-config
export C_MIMIR_TEST_CLANG=/opt/llvm/bin/clang
export C_MIMIR_TEST_AR=/opt/llvm/bin/llvm-ar
nice -n 10 cargo test --manifest-path crates/c-mimir-dump/Cargo.toml --jobs 8
Capture a build
Set the wrappers in the build's environment:
export CC=c-mimir-cc CXX=c-mimir-cxx AR=c-mimir-ar
export C_MIMIR_OUT=/output/capture
make -C /output/build -j8
c-mimir-dump read /output/capture --out /output/graph --unit my-program
The original compiler receives the original arguments, including response-file arguments. After a successful compilation, a second clang command generates bitcode with line-table debug information. An original compiler failure or signal is propagated; failed IR capture exits nonzero. Compiler probes do not trigger recursive version probes. Capture always regenerates bitcode, so a changed included header cannot reuse an old source-only cache entry.
Source discovery honors positional -x language selection, including joined forms such as -xc, and preprocessed C++ .ii inputs. Preprocessing and assembly commands are forwarded as pass-through operations. C/C++ stdin compilation and unsupported explicit languages fail with a capture error; stdin bytes cannot be replayed for the second compiler invocation.
Defaults point to /opt/llvm/bin/clang, clang++, and llvm-ar. Override them with absolute C_MIMIR_CLANG, C_MIMIR_CXX, C_MIMIR_AR, or C_MIMIR_LD paths. c-mimir-ld defaults to the clang linker driver. Set C_MIMIR_LD to the pinned ld.lld when the build invokes a linker directly. Do not point a real-tool variable back to a wrapper.
A capture contains content-addressed .bc files and atomic per-TU .cmd.json records. Records preserve the original and expanded argv, cwd, source/object, compiler version, bitcode/source SHA-256, and Cargo's package name, version, OUT_DIR and TARGET. Archive wrappers record the real archive's membership after normal mutations, including replacement and deletion. Link records retain direct input paths and unresolved -l tokens. MRI archive scripts are rejected for capture. Arguments and recorded paths must be UTF-8. Archive capture rejects ambiguous duplicate member names and members with no recorded input path. Wrap archive creation as well as subsequent mutations; preexisting archives without capture records cannot supply inferred membership. Thin-archive listings with explicit paths preserve distinct same-named inputs.
Reader format 8 writes a function declaration with extern_weak linkage with the role weak-import (every other declaration stays import); a reader that knows only formats up to 7 refuses the tables.
Reader format 7 adds typed, exact scalar half/bfloat/float/double operand bits. Execution keeps these values unknown; capture does not authorize floating-point branch pruning. Wider floats, vectors and pointer expressions stay unresolved. The reader revision is part of the cache key, so older cached tables rebuild.
Wrapper records also contain native_output_sha256 and tool_sha256. Native object, executable and archive files are hashed after the original command and checked again before records are published. The invoked tool is hashed before the original command and checked through capture. An observed change, unreadable file or missing expected output fails capture and invalidates previous records. Failed original commands still retain their exit status or terminating signal. Hashing streams files instead of loading native binaries into memory.
These fields are byte observations, not a link-selection certificate. They do not cover a tool's libraries/plugins, an archive's external thin members, or the inputs to the separate native and IR compilations. Before/after checks do not prevent a concurrent change that is restored between checks; trusted immutable build inputs and full linker provenance are still required. Existing link input paths and -l tokens cannot authorize selecting a source definition.
Legacy records leave both new fields absent. A compilation-database replay sets both to null: it emits IR and does not identify a native build. A combined compile and link command identifies the final executable in its link record; its per-TU records have no native object digest because no persistent per-TU object was produced. No graph path is closed by these new observations alone.
Reader format 6 gives each captured compilation a scope of package@version#compilation-digest (without @version when unknown). The digest covers the capture slot, verified bitcode, compiler version and expanded arguments. This keeps two objects built from the same source, such as PIC and non-PIC builds, from colliding. Package metadata stays unchanged. Replaying the same capture keeps the same identities; older graph caches are not reused. Distinct compiled definitions of an exported symbol still need native binding evidence to select a target.
For a cargo build, cargo mimir make --with-c (nornir-mimir-bin) sets these variables itself, reads the capture into <out>/c-source and merges it into every program's graph beside the Rust dump.
Read a compilation database
c-mimir-dump compdb /source/compile_commands.json --out /output/capture --unit my-program
Both arguments arrays and quoted command strings are accepted. Each entry's working directory is respected. Only the IR command runs; native object outputs are untouched. The graph is written under /output/capture/graphs. Use a dedicated capture directory for each database: after successful capture, records for translation units removed from the database are pruned. A persistent incomplete marker blocks read after a failed capture. Rerun compdb successfully to clear it before publishing a new graph.
Graph publication and incremental reads
read CAPTURE_DIR --out OUTPUT --unit NAME verifies every captured bitcode digest before reading it with the pinned LLVM C API. It publishes immutable table sets under OUTPUT/objects/<content-key>/ and then atomically replaces OUTPUT/manifest.json. Consumers must read the files listed in that manifest; they must not glob every cached file. Unreferenced cache objects can remain from older successful runs. Failed reads preserve the previous committed manifest.
Content keys include the bitcode digest, source, unit/package identity, package version, reader version, graph format revision and repository provenance. An unchanged translation unit reuses its table set. A successful manifest lists every current translation unit and its files, so removed inputs cannot remain part of a newly published graph. The explicit unit name groups ordinary C inputs. Captured Cargo package names and versions own their C nodes so they can join their Rust package's graph.
Graph reader revision 5 uses name@version as the identity scope when the package version is known. This scopes node and data identities, function references, block/unresolved module identities, and the manifest's translation-unit unit. For example, versions 48.0.8 and 49.0.5 of wasmtime cannot share C monikers. The crate metadata column remains wasmtime, with the version in its own column. Empty or unknown versions retain the old unversioned name; custom unit names must reserve @ for the version delimiter.
The source capture loader accepts reader revisions 3 through 6. Regenerate older captures to obtain version-scoped identities; changing a manifest version alone does not rewrite its tables. This reader/cache revision is independent of the capture manifest schema version (1) and LLVM body schema version (2). Package version alone does not distinguish different features, targets, compiler options or build-script output. Reader format 6 adds the compilation identity described above; it distinguishes captured compilations but does not prove which objects belong to a native executable. Keep separate native build contexts and their membership evidence explicit.
Archive/link records do not establish that all linked code was captured; the manifest states that limitation.
The reader writes Mímir's existing node, edge, span, symbol and block schemas. Any additive source facts use the shared schema crate. Unsupported or unresolved LLVM constructs remain reader notes; no separate private graph schema is used.
Run the build in a rootless container
Create separate existing directories for rootfs, source, output and runtime state; they must not overlap. Run as an unprivileged user with user namespaces and a delegated systemd cgroup service:
c-mimir-dump run \
--rootfs /absolute/image-rootfs \
--image-digest sha256:REPLACE_WITH_VERIFIED_64_HEX_IMAGE_MANIFEST_DIGEST \
--source /absolute/project-source \
--output /absolute/build-output \
--state /absolute/runtime-state \
-- cmake -S /source -B /output/build
The runtime mounts /source read-only and /output read-write, starts in /output, and supplies wrappers in CC, CXX and AR. Its private network namespace has no host network access. Fetch sources and dependencies beforehand. Pass deliberate environment overrides with repeated --env NAME=value options. The runtime enforces eight CPU equivalents, 64 GiB memory with no additional swap, and 4,096 processes; inability to enforce cgroup limits fails the run. Runtime state is private and cleaned after exit; failed cleanup reports its recovery path.
On Ubuntu hosts restricting unprivileged user namespaces:
c-mimir-dump apparmor-profile > c-mimir-dump.apparmor
Review and install the rendered profile through the host's administrator workflow. The command only prints the profile for the current executable and does not edit host policy.
The heimdall-seccomp feature is off by default. Its optional adapter uses crates.io nordisk-heimdall-youki 0.1.0 and nordisk-libcontainer 0.7.0, which share the SeccompBackend trait. Default builds use crates.io libcontainer 0.7.0. These dependencies are MIT OR Apache-2.0; no AGPL crate is linked by this feature. Cargo.lock records the resolved versions.
The current lockfile has no Git dependencies. The container recipe still expects a cargo-git-db build-context directory; create it empty for this lockfile. No SSH keys, credentials or host checkouts are needed. Registry fetching is a provisioning step, and the release compilation runs offline with no network.
Build with --features heimdall-seccomp, then select the backend and provide a measured OCI seccomp section together:
c-mimir-dump run ... --heimdall-seccomp --seccomp-profile /absolute/workload.oci.json -- COMMAND...
The profile is read once, hashed, and checked by Heimdall's pure compiler before container creation. It must be an enforcing profile for the host architecture; allow-all defaults, unsupported operations, and listener/USER_NOTIF profiles are rejected. This executor does not implement broker descriptor handoff.
The pinned fork exposes SeccompBackend and with_executor, but its ordinary OCI linux.seccomp path still selects libseccomp. The runtime therefore omits that standard section for this optional backend and installs one Heimdall filter through its executor immediately before the default executor calls execvp. It records the backend name, exact profile SHA-256 and executor-before-exec installation method in OCI annotations. Namespace setup, no_new_privs, and capability dropping finish before this hook. The executor checks those security settings and fails if a second OCI seccomp installer is present.
Normal feature tests only compile profiles/BPF and inspect OCI specifications; they never install a kernel filter. The ignored feature lifecycle test may run only in a throwaway VM, with a measured profile supplied by its operator. Do not enable ignored seccomp lifecycle tests on the host or in an ordinary build container. The feature's kernel lifecycle remains unverified until that VM test is run.
Link selection authority
A link record has selection_authority: true only when the link used LLD (-fuse-ld=lld or ld.lld) and a report-only relink of the same argv, adding --why-extract, --dependency-file and --trace and writing a scratch output, produced the same bytes as the build's link, and every archive member it loaded is attributed. --trace names every loaded member; --why-extract names only the lazy extractions (with the reference and the symbol). A member it does not name must come from an archive the linker reads inside --whole-archive (reference --whole-archive, no symbol). For a compiler driver the linker's own command line is the one the driver prints under -###, since the driver adds --whole-archive itself around a sanitizer runtime. A lazy member --trace did not load, or a loaded member with no reason, leaves the record without authority. Then link_inputs lists every file the linker read with its SHA-256, and extracted every archive member it loaded (archive, member, member SHA-256, reference, symbol). Otherwise the record keeps selection_refusal with the reason. Definition selection may use only records with authority; weak and versioned resolution, LTO and section GC are not yet recorded.