Skip to content

TimeDateStamp in object files should be a deterministic hash #21095

Open
@dkorpel

Description

@dkorpel

#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compiler:Backendglue code, optimizer, code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions