emacs: pin clock_gettime in fixrand shim for reproducible .pdmp - #273
Conversation
After the existing fixrand.so shim (getrandom/urandom), the dumped .pdmp still differed in 11 bytes — two wall-clock timestamps read via clock_gettime(CLOCK_REALTIME), which the shim didn't cover: the *scratch* buffer's buffer-display-time (Fcurrent_time in make_initial_frame) and Vgc_elapsed GC timing (src/alloc.c). Extend the shim to return SOURCE_DATE_EPOCH for CLOCK_REALTIME (other clocks pass through). Verified on aarch64: two from-scratch builds are byte-identical (repro-check diff, 4282/4282 files). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
Changesclock_gettime determinism shim
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/emacs/fixrand.c`:
- Around line 75-85: The real_clock_gettime function pointer can remain NULL if
dlsym fails to load the symbol, which will cause a NULL pointer dereference when
called for non-CLOCK_REALTIME clock IDs. Add a NULL check for real_clock_gettime
before calling it on the final return statement, and either log an error or
return an appropriate error code (such as -1 with errno set to ENOSYS) if the
symbol lookup failed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9567d1f9-d904-47db-ac7c-949595cb483a
📒 Files selected for processing (1)
packages/emacs/fixrand.c
Defensive NULL check before deref of real_clock_gettime: if dlsym(RTLD_NEXT, "clock_gettime") ever returns NULL, fail with ENOSYS instead of segfaulting. The CLOCK_REALTIME path already returns before this point, so this only affects pass-through clocks (CLOCK_MONOTONIC, etc.) — but it makes the shim robust regardless. Folds in the one valid point from the Edge Delta bot's #278. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
What
Makes the
emacspackage reproducible by extending the existingfixrand.soLD_PRELOAD shim to also pinclock_gettime(CLOCK_REALTIME).Why
After the current shim (which makes
getrandom()//dev/urandomdeterministic for hash-table seeding), the dumpedemacs-*.pdmpstill differed across builds — in exactly 11 bytes, in two clusters, both decoding to wall-clock timestamps captured at dump time viaclock_gettime(CLOCK_REALTIME)(which the shim didn't intercept):*scratch*buffer'sbuffer-display-time— an Emacs(TICKS . HZ)timestamp cons set byFcurrent_time()duringmake_initial_frame(src/window.c/src/emacs.c). The two builds decoded to2026-06-16 04:01:42vs04:02:43— exactly the ~61s gap between them.Vgc_elapsed— accumulated GC time (a float) insrc/alloc.c, measured withcurrent_timespec().SOURCE_DATE_EPOCHdoesn't help here because Emacs reads the live clock directly.Fix
Add a
clock_gettimeinterceptor tofixrand.cthat returnsSOURCE_DATE_EPOCHforCLOCK_REALTIME(and passes all other clocks, e.g.CLOCK_MONOTONIC, through untouched so timeouts/progress loops are unaffected). The build.sh compile line is unchanged — it already buildsfixrand.cwith-ldl.This pins the display-time and makes GC
start == end(elapsed0.0), both deterministic. No literalSOURCE_DATE_EPOCH=0(usesgetenv+ fallback), so it passesminimal-check.Verification
Build-twice-and-diff on aarch64: two from-scratch builds are now byte-for-byte identical (
repro-check diff, 4282/4282 files). Before, the.pdmpdiffered in 11 timestamp bytes.🤖 Generated with Claude Code
Summary by CodeRabbit