Making /var/cache/ldconfig/aux-cache reproducible is a common challenge in reproducible build environments. The aux-cache is a binary cache generated by ldconfig that stores auxiliary information about shared libraries (like their dependencies and versions) to speed up ldconfig operations.
Its non-reproducibility usually stems from:
- Non-deterministic input: Differences in library files (even minor metadata like timestamps or build IDs), or configuration files (
/etc/ld.so.conf, /etc/ld.so.conf.d/).
- Non-deterministic environment: Locale settings, timezone, current time, filesystem traversal order,
ldconfig version.
- Internal
ldconfig behavior: The order in which ldconfig processes libraries or records information might not be stable across runs if inputs are not strictly controlled, or if it embeds timestamps/non-deterministic data.
Here's a comprehensive approach to make it reproducible:
Key Principles for Reproducibility
- Identical Inputs: Every file that
ldconfig reads must be byte-for-byte identical across builds.
- Identical Environment: The execution environment for
ldconfig must be the same (locale, time, umask, etc.).
- Identical Toolchain: The exact same version of
ldconfig (and potentially glibc it links against) must be used.
Specific Steps to Achieve Reproducibility
1. Ensure Reproducible Library Files
This is the most critical step. If the shared libraries themselves aren't reproducible, aux-cache cannot be.
- Strip non-deterministic data: Ensure all compiled shared libraries (
.so files) are stripped of build paths, timestamps, build IDs, and other non-deterministic debug information. Tools like strip and objcopy --redefine-sym can help, but ideally, your compiler flags for reproducible builds (e.g., gcc -fmacro-prefix-map=... -fdebug-prefix-map=... -gno-record-gcc-switches) should handle this.
- Normalized timestamps: Ensure that all input files (libraries, configuration files) have normalized modification times. When creating tarballs or
rsyncing files, use options like --mtime=@0 or -a --no-o --no-g --no-p to prevent timestamps from varying.
2. Standardize ldconfig Configuration Files
/etc/ld.so.conf: This file should be identical across builds.
/etc/ld.so.conf.d/:
- Ensure the contents of all files within this directory are identical.
ldconfig typically processes files in this directory in lexical order. Ensure your build system or deployment process creates these files with consistent names and that the underlying filesystem doesn't introduce non-deterministic ordering (though this is rare for readdir).
3. Control ldconfig Execution Environment
4. Use a Consistent ldconfig Version
- Ensure the exact same version of the
ldconfig utility and the glibc it links against is used across all build environments. Minor version differences can introduce changes in the cache format or internal processing order.
5. Verify Reproducibility
After implementing these steps, run your build multiple times and compare the aux-cache file:
# First build
<your_reproducible_build_script>
sudo faketime '2000-01-01 00:00:00' ldconfig
sha256sum /var/cache/ldconfig/aux-cache > aux-cache.sum1
# Second build (e.g., in a clean environment or after changing a dummy file)
<your_reproducible_build_script>
sudo faketime '2000-01-01 00:00:00' ldconfig
sha256sum /var/cache/ldconfig/aux-cache > aux-cache.sum2
diff aux-cache.sum1 aux-cache.sum2
If diff shows no output, you've likely achieved reproducibility for this file.
Advanced Debugging (if non-reproducible)
If the aux-cache still isn't reproducible, you'll need to dig deeper:
- Examine the
aux-cache content:
- It's typically a GDBM or DBM database file. You can try
strings /var/cache/ldconfig/aux-cache to see if any human-readable paths or timestamps are embedded.
- For a deeper look, use
hexdump -C /var/cache/ldconfig/aux-cache. Compare the hex dumps between two non-reproducible runs to pinpoint differing bytes.
strace ldconfig: Run ldconfig with strace to see every system call it makes. Look for stat() calls (which expose modification times), time() calls, or getrandom()//dev/urandom reads that might introduce non-determinism.
strace -o ldconfig.strace.log faketime '2000-01-01 00:00:00' ldconfig
Compare two strace logs from non-reproducible runs.
By meticulously controlling the inputs, environment, and ldconfig execution, you should be able to make /var/cache/ldconfig/aux-cache reproducible.