Skip to content

Commit cd66db6

Browse files
committed
Add build time to reproducible builds
1 parent a16cdd8 commit cd66db6

5 files changed

Lines changed: 84 additions & 12 deletions

File tree

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ include $(META)
2929
export VERSION := $(VBASE).$(VMAJOR).$(VMINOR)
3030
export PATH := $(subst ;;,;,$(PATH);$(shell getGnuWin32Path))
3131
export BUILD_TIME:=$(shell getCommitTime)
32+
export BUILD_TIME_UNIX:=$(shell getCommitTime unix)
3233
ifneq ($(BUILD_TIME),)
3334
$(info Build time is set to $(BUILD_TIME))
3435
else
@@ -63,7 +64,6 @@ NSIS := makensis
6364
NASM := nasm
6465
LINKER := golink
6566
RCCOMP := gorc
66-
REPRO := ducible
6767
GETBINLIST := $(call FixPath,./getBinList)$(SCRIPTEXT)
6868
EXTRACTSYM := $(call FixPath,./extractSymbols)$(SCRIPTEXT)
6969
VERIFYSIZE := $(call FixPath,./verifySize)$(SCRIPTEXT)
@@ -246,13 +246,11 @@ $(SETUP) : $(LOADER) $(TARGET) LICENSE $(SETUPSCR) $(SETUPINI)
246246
$(LOADER) : $(LOADER_OBJ) $(TARGET)
247247
@$(call mkdir,$(BUILDDIR))
248248
$(LINKER) $(FLAGS_L) /fo $(call FixPath,$@) $^ $(LOADER_SYSDEP)
249-
$(REPRO) $@
250249
$(PATCHREPRO) $(call FixPath,$@)
251250

252251
$(TARGET) : $(OBJ) $(RSC)
253252
@$(call mkdir,$(BUILDDIR))
254253
$(LINKER) $(FLAGS_L) /fo $(call FixPath,$@) $^ $(SYSDEP)
255-
$(REPRO) $@
256254
$(PATCHREPRO) $(call FixPath,$@)
257255

258256
$(LOADER_OBJ) : $(LOADER_SRC)
@@ -266,7 +264,7 @@ $(OBJ) : $(SRCDLL) $(CONTENT) $(IKLG)
266264
# Overwrite MemoryFlags (0x36 WORD) in the RES Header which sometimes varies across builds on different machines
267265
$(RSC) : $(RC)
268266
$(RCCOMP) $(FLAGS_RC) /fo $@ /r $^
269-
ECHO -n 0000 | xxd -r -p | dd of=$@ bs=1 seek=54 count=2 conv=notrunc > nul 2>&1
267+
ECHO -n 0000 | xxd -r -p | dd of=$@ bs=1 seek=54 count=2 conv=notrunc status=none
270268

271269
$(CONTENT) : $(BINARIES_G1) $(BINARIES_G112) $(BINARIES_G130) $(BINARIES_G2)
272270
$(GETBINLIST) $(call FixPath,$@) $(SRCDIR)

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Additionally, you'll need the following binaries:
6464
- [GNU Make](http://gnuwin32.sourceforge.net/packages/make.htm) (3.81)
6565
- [Git for Windows](https://git-scm.com/download/win) (2.45.1) for various included GNU Win32 tools
6666
- [BinUtils](https://sourceforge.net/projects/mingw/files/MinGW/Base/binutils/) (2.28) for `objdump`
67-
- [ducible](https://github.com/jasonwhite/ducible) (1.2.2)
6867

6968
The binaries of the listed software must be added to your `PATH` environment variable or placed in the root directory.
7069

getCommitTime.bat

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
:: Get build time from last git revision
33
:: To be effetive, requires git and this project to be cloned
44
::
5-
:: Arguments: none
5+
:: Arguments: [UNIX]
66
::
77
@ECHO OFF
88
SETLOCAL
99

10+
:: Sanity check
11+
IF "%~1"=="" SET unix=0&& GOTO start
12+
IF "%~1"=="unix" SET unix=1&& GOTO start
13+
IF "%~1"=="UNIX" SET unix=1&& GOTO start
14+
ECHO Usage: %~nx0 [UNIX]
15+
EXIT /B 0
16+
:start
17+
1018
:: Check for git
1119
where git> nul 2>&1
1220
IF NOT %ERRORLEVEL%==0 EXIT /B 0
@@ -19,6 +27,9 @@ IF NOT %ERRORLEVEL%==0 EXIT /B 0
1927
FOR /F "usebackq" %%i IN (`git log -1 --format^=%%at`) DO SET "timestamp=%%i"
2028
SET parameters=-u -d @"%timestamp%" +"%%Y-%%m-%%d %%H:%%M:%%S"
2129

30+
:: Unix time stamp
31+
IF "%unix%"=="1" ECHO %timestamp% && EXIT /B 0
32+
2233
:: Attempt to find unix "date"
2334
where date> nul 2>&1
2435
IF NOT %ERRORLEVEL%==0 EXIT /B 0

patchBuildBytes.bat

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ IF [%1] == [] GOTO usage
1414
SET "file=%~1"
1515
SET filebase=%~n1
1616

17+
:: Convert unix timestamp to hexadecimal and flip endianness
18+
CMD /C EXIT %BUILD_TIME_UNIX%
19+
SET "BUILD_TIME_HEX=%=ExitCode%"
20+
SET "BUILD_TIME_HEX=%BUILD_TIME_HEX:~-4,4%%BUILD_TIME_HEX:~0,4%"
21+
1722
:: Use objdump to get a summary of the file to later compare patched bytes
1823
objdump -x %file% > %file%.txt
1924

@@ -55,7 +60,7 @@ FOR /F "tokens=1" %%A IN (iat.txt) DO (
5560
SET /A "hex_dec=0x!hex!"
5661
SET /A "addr=!hex_dec!-!idata_vma!+!idata_offset!"
5762
:: Zero out ordinal number at address (WORD)
58-
ECHO -n 0000 | xxd -r -p | dd of=%file% bs=1 seek=!addr! count=2 conv=notrunc > nul 2>&1
63+
ECHO -n 0000 | xxd -r -p | dd of=%file% bs=1 seek=!addr! count=2 conv=notrunc status=none
5964
)
6065
DEL /Q iat.txt
6166

@@ -91,10 +96,69 @@ FOR /F "tokens=5" %%A IN (dlltables.txt) DO (
9196
)
9297
CALL :strlen name len
9398
:: Convert name to uppercase
94-
dd if=%file% of=%file% bs=1 seek=!addr! skip=!addr! count=!len! conv=ucase,notrunc > nul 2>&1
99+
dd if=%file% of=%file% bs=1 seek=!addr! skip=!addr! count=!len! conv=ucase,notrunc status=none
95100
)
96101
DEL /Q dlltables.txt
97102

103+
:: Next: Remove time stamps from file header
104+
105+
:: Find offset of FILE_HEADER
106+
dd if=%file% bs=1 skip=60 count=4 2> nul | od -An -t u4 -N4 > header.txt
107+
FOR /F "tokens=1" %%a IN (header.txt) DO (
108+
SET /A "file_header_offset=%%a+4"
109+
)
110+
DEL /Q header.txt
111+
112+
ECHO FILE_HEADER: %file_header_offset%
113+
114+
:: Set FILE_HEADER time stamp
115+
SET /A "timestamp_offset=file_header_offset + 4"
116+
ECHO -n %BUILD_TIME_HEX% | xxd -r -p | dd of=%file% bs=1 seek=%timestamp_offset% count=4 conv=notrunc,swab status=none
117+
118+
:: Next: Remove the check sum from optional header
119+
120+
:: Find offset of the optional header
121+
SET /A "optional_header_offset=file_header_offset+32"
122+
ECHO OPTIONAL_HEADER: %optional_header_offset%
123+
124+
:: Set optional header checksum
125+
SET /A "checksum_offset=optional_header_offset + 52"
126+
ECHO -n 00000000 | xxd -r -p | dd of=%file% bs=1 seek=%checksum_offset% count=4 conv=notrunc status=none
127+
128+
:: Next: Set the image version
129+
130+
:: Find the version offset
131+
SET /A "image_version_offset=optional_header_offset + 32"
132+
ECHO IMAGE_VERSION: %image_version_offset%
133+
134+
:: Build hexadecimal version with switched endianness
135+
SET "VERSION_H_DEC=%VBASE%%VMAJOR%"
136+
CMD /C EXIT %VERSION_H_DEC%
137+
SET "VERSION_H_HEX=%=ExitCode%"
138+
SET "VERSION_H_HEX=%VERSION_H_HEX:~-2,2%%VERSION_H_HEX:~-4,2%"
139+
CMD /C EXIT %VMINOR%
140+
SET "VERSION_L_HEX=%=ExitCode%"
141+
SET "VERSION_L_HEX=%VERSION_L_HEX:~-2,2%%VERSION_L_HEX:~-4,2%"
142+
SET "VERSION_HEX=%VERSION_H_HEX%%VERSION_L_HEX%"
143+
144+
:: Set the image version
145+
ECHO -n %VERSION_HEX% | xxd -r -p | dd of=%file% bs=1 seek=%image_version_offset% count=4 conv=notrunc status=none
146+
147+
:: Next: Remove time stamps from export table
148+
149+
:: Find offset of .edata section
150+
objdump -h -j .edata %file% | findstr "\.edata" > header.txt
151+
FOR /F "tokens=6" %%a IN (header.txt) DO (
152+
SET /A "edata_offset=0x%%a"
153+
)
154+
DEL /Q header.txt
155+
156+
ECHO IMAGE_EXPORT_DIRECTORY: %edata_offset%
157+
158+
:: Set IMAGE_EXPORT_DIRECTORY time stamp
159+
SET /A "timestamp_offset=edata_offset + 4"
160+
ECHO -n %BUILD_TIME_HEX% | xxd -r -p | dd of=%file% bs=1 seek=%timestamp_offset% count=4 conv=notrunc,swab status=none
161+
98162
:: Next: Remove time stamps from resource table
99163

100164
:: Find size and offset of .rsrc section
@@ -113,15 +177,15 @@ IF "%rsrc_size%" NEQ "768" ECHO Warning: Resource directory sections is of unexp
113177

114178
:: Type Table Time
115179
SET /A "timestamp_offset=rsrc_offset + 4"
116-
ECHO -n 003b3d4b | xxd -r -p | dd of=%file% bs=1 seek=%timestamp_offset% count=4 conv=notrunc > nul 2>&1
180+
ECHO -n %BUILD_TIME_HEX% | xxd -r -p | dd of=%file% bs=1 seek=%timestamp_offset% count=4 conv=notrunc,swab status=none
117181

118182
:: Name Table Time
119183
SET /A "timestamp_offset=rsrc_offset + 28"
120-
ECHO -n 003b3d4b | xxd -r -p | dd of=%file% bs=1 seek=%timestamp_offset% count=4 conv=notrunc > nul 2>&1
184+
ECHO -n %BUILD_TIME_HEX% | xxd -r -p | dd of=%file% bs=1 seek=%timestamp_offset% count=4 conv=notrunc,swab status=none
121185

122186
:: Language Table Time
123187
SET /A "timestamp_offset=rsrc_offset + 52"
124-
ECHO -n 003b3d4b | xxd -r -p | dd of=%file% bs=1 seek=%timestamp_offset% count=4 conv=notrunc > nul 2>&1
188+
ECHO -n %BUILD_TIME_HEX% | xxd -r -p | dd of=%file% bs=1 seek=%timestamp_offset% count=4 conv=notrunc,swab status=none
125189

126190
:CLEANUP
127191

src/dll/Ninja.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extern WriteFile
6363
extern CloseHandle
6464
extern DeleteFileA
6565

66-
export DllMain
66+
global DllMain
6767
export Ninja
6868

6969
section .data

0 commit comments

Comments
 (0)