Source: emacs24
Version: 24.5+1-6
Severity: wishlist
Tags: patch upstream
Usertags: toolchain

Dear Maintainer,

When bytecompiling elisp files, cl-gensym-counter is initialized from
the current time, leading to unreproducible results. This can affect
reproducibility [1] of some software packages that build-depend on emacs
(and of emacs24 itself). I suggest to set the initial value of
cl-gensym-counter from the names of the files to be compiled (see
proposed patch).


cd /tmp
emacs -batch --no-site-file --no-site-lisp -f batch-byte-compile ob-C.el
cp ob-C.elc ob-C.elc.0
sleep 1
emacs -batch --no-site-file --no-site-lisp -f batch-byte-compile ob-C.el
diff ob-C.elc ob-C.elc.0

The two files should be the same, but they differ (with different #:Gnnn

Alexis Bienvenüe.


Description: Reproducible gensym-counter
 When calling batch-byte-compile, set the start value of gensym-counter from
 a hash of the command-line arguments instead of time, so that the compiled
 files can be reproducible.
Author: Alexis Bienvenüe <>

Index: emacs24-24.5+1/lisp/emacs-lisp/bytecomp.el
--- emacs24-24.5+1.orig/lisp/emacs-lisp/bytecomp.el
+++ emacs24-24.5+1/lisp/emacs-lisp/bytecomp.el
@@ -4625,6 +4625,10 @@ already up-to-date."
   (if (not noninteractive)
       (error "`batch-byte-compile' is to be used only with -batch"))
   (let ((error nil))
+    ;; Init gensym-counter from command-line arguments instead of
+    ;; time, to get a reproducible result.
+    (cl-init-gensym-counter
+     (mapconcat 'identity (sort command-line-args-left 'string<) ";"))
     (while command-line-args-left
       (if (file-directory-p (expand-file-name (car command-line-args-left)))
 	  ;; Directory as argument.
Index: emacs24-24.5+1/lisp/emacs-lisp/cl-lib.el
--- emacs24-24.5+1.orig/lisp/emacs-lisp/cl-lib.el
+++ emacs24-24.5+1/lisp/emacs-lisp/cl-lib.el
@@ -261,6 +261,12 @@ so that they are registered at compile-t
 (defvar cl--gensym-counter (* (logand (cl--random-time) 1023) 100))
+(defun cl-init-gensym-counter (string)
+  "Set gensym-counter from a hash of string."
+  (setq cl--gensym-counter (* (logand
+                               (string-to-number (substring (secure-hash 'sha1 string) -3) 16)
+                               1023) 100)))
 ;;; Numbers.
Reproducible-builds mailing list

Reply via email to