Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeDateStamp in object files should be a deterministic hash #21095

Open
dkorpel opened this issue Mar 27, 2025 · 0 comments
Open

TimeDateStamp in object files should be a deterministic hash #21095

dkorpel opened this issue Mar 27, 2025 · 0 comments
Labels
Compiler:Backend glue code, optimizer, code generation

Comments

@dkorpel
Copy link
Contributor

dkorpel commented Mar 27, 2025

#20985 once again highlighted the importance of reproducible builds. While investigating that, I noticed time-based differences in the built executables. That's because the backend writes a timestamp to the header:

time_t f_timedat = 0;
time(&f_timedat);
uint symtable_offset;
if (bigobj)
{
header.Sig1 = IMAGE_FILE_MACHINE_UNKNOWN;
header.Sig2 = 0xFFFF;
header.Version = 2;
header.Machine = I64 ? IMAGE_FILE_MACHINE_AMD64 : IMAGE_FILE_MACHINE_I386;
header.NumberOfSections = scnhdr_cnt;
header.TimeDateStamp = cast(uint)f_timedat;

After looking into what that field is even used for, I found:

https://devblogs.microsoft.com/oldnewthing/20180103-00/?p=97705

One of the changes to the Windows engineering system begun in Windows 10 is the move toward reproducible builds. This means that if you start
with the exact same source code, then you should finish with the exact same binary code.

The timestamp is really a unique ID that tells the loader, “The exports of this DLL have not changed since the last time anybody bound to it.” And a hash is a reproducible unique ID.

I think dmd should follow this example. Not just for MSCoff, also for ELF and MachObj.

@dkorpel dkorpel added the Compiler:Backend glue code, optimizer, code generation label Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compiler:Backend glue code, optimizer, code generation
Projects
None yet
Development

No branches or pull requests

1 participant