]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
examples:winexe: reproducible builds with zero timestamp
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Mon, 27 May 2024 23:34:51 +0000 (11:34 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 31 May 2024 00:25:33 +0000 (00:25 +0000)
Windows Portable Executable files have a timestamp field and a
checksum field. By default the timestamp field is updated to the
current time, which consequently changes the checksum. This makes the
build nondeterministic. It looks like this:

  --- a/tmp/winexe-1/winexesvc64_exe_binary.c
  +++ b/tmp/winexe-2/winexesvc64_exe_binary.c
  @@ -23,7 +23,7 @@ const DATA_BLOB *winexesvc64_exe_binary(void)
                0x6D, 0x6F, 0x64, 0x65, 0x2E, 0x0D, 0x0D, 0x0A,
                0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x50, 0x45, 0x00, 0x00, 0x64, 0x86, 0x0A, 0x00,
  -             0xB2, 0x16, 0x55, 0x66, 0x00, 0x00, 0x00, 0x00,
  +             0xD3, 0x3B, 0x55, 0x66, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x2E, 0x02,
                0x0B, 0x02, 0x02, 0x26, 0x00, 0x86, 0x00, 0x00,
                0x00, 0xBA, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
  @@ -33,7 +33,7 @@ const DATA_BLOB *winexesvc64_exe_binary(void)
                0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x40, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00,
  -             0x73, 0xD7, 0x00, 0x00, 0x03, 0x00, 0x60, 0x01,
  +             0x94, 0xFC, 0x00, 0x00, 0x03, 0x00, 0x60, 0x01,
                0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,

https://learn.microsoft.com/en-us/windows/win32/debug/pe-format says
that a timestamp of zero can be used to represent a time that is not
"real or meaningful", so we do that.

As far as I can tell, the timestamp and checksum are only used in
DLLs, not directly executed .exe files.

Thanks to Freexian and the Debian LTS project for sponsoring this work.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13213

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
examples/winexe/wscript
examples/winexe/wscript_build

index 6b311b1da41537cf6b997381b36031bc4eaf0c6a..a202282e76564fb8609404b38a81127d9c40a4ad 100644 (file)
@@ -1,4 +1,6 @@
 #!/usr/bin/env python
+import os
+
 
 def configure(conf):
     AR32 = ['i386', 'i586', 'i686']
@@ -27,5 +29,17 @@ def configure(conf):
             conf.DEFINE('HAVE_WINEXE_CC_WIN64', 1);
             break
 
+    source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH')
+    if source_date_epoch is None:
+        # We set the timestamp to be 0, which makes the winexe build
+        # reproducible. According to
+        # https://learn.microsoft.com/en-us/windows/win32/debug/pe-format
+        #
+        # > If the stamp value is 0 or 0xFFFFFFFF, it does not
+        # > represent a real or meaningful date/time stamp.
+
+        source_date_epoch = '0'
+
+    conf.env.SOURCE_DATE_EPOCH = source_date_epoch
     conf.DEFINE("WINEXE_LDFLAGS",
                 "-s -Wall -Wl,-Bstatic -Wl,-Bdynamic -luserenv")
index a9de34739488a990e939033c60126fc733fe948c..faec560bc888750be1170029172dc4bef97029a3 100644 (file)
@@ -58,7 +58,7 @@ bld.SAMBA_GENERATOR(
     'winexesvc32_exe',
     source='winexesvc.c',
     target='winexesvc32.exe',
-    rule='${WINEXE_CC_WIN32} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
+    rule='SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} ${WINEXE_CC_WIN32} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
     enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN32)
 
 vars = {"WINEXE_FN": "winexesvc32_exe_binary"}
@@ -78,7 +78,7 @@ bld.SAMBA_GENERATOR(
     'winexesvc64_exe',
     source='winexesvc.c',
     target='winexesvc64.exe',
-    rule='${WINEXE_CC_WIN64} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
+    rule='SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} ${WINEXE_CC_WIN64} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
     enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN64)
 
 vars = {"WINEXE_FN": "winexesvc64_exe_binary"}