@@ -36,8 +36,6 @@ import dmd.backend.mscoff;
3636
3737import dmd.common.outbuffer;
3838
39- import dmd.root.hash : calcHash;
40-
4139nothrow :
4240@safe :
4341
@@ -651,29 +649,11 @@ void MsCoffObj_term(const(char)[] objfilename)
651649 BIGOBJ_HEADER header = void ;
652650 IMAGE_FILE_HEADER header_old = void ;
653651
654- // Calculate a deterministic hash instead of using the current time
655- // Use a hash of all section data to ensure deterministic builds
656- uint f_timedat = 0 ;
657- // Hash sections and their contents for deterministic timestamp
658- import dmd.root.hash : calcHash;
659- // Collect all section data to hash
660- OutBuffer hashBuf;
661- for (segidx_t seg = 1 ; seg < SegData.length; seg++ )
662- {
663- seg_data* pseg = SegData[seg];
664- if (pseg.SDbuf && pseg.SDbuf.length())
665- {
666- // Add segment contents to the buffer
667- hashBuf.write(pseg.SDbuf.buf[0 .. pseg.SDbuf.length()]);
668- }
669- }
670-
671- // Calculate the hash based on all sections
672- if (hashBuf.length > 0 )
673- f_timedat = calcHash(hashBuf.buf[0 .. hashBuf.length]);
652+ // Initialize headers to ensure no uninitialized memory affects hashing
653+ memset(&header, 0 , header.sizeof);
654+ memset(&header_old, 0 , header_old.sizeof);
674655
675- // Add fixed value to make the hash recognizable (timestamp starts from 1970)
676- f_timedat = (f_timedat & 0x7FFFFFFF ) | 0x40000000 ; // Make sure it's a reasonable timestamp
656+ time_t f_timedat = 0 ;
677657 uint symtable_offset;
678658
679659 if (bigobj)
@@ -683,7 +663,7 @@ void MsCoffObj_term(const(char)[] objfilename)
683663 header.Version = 2 ;
684664 header.Machine = I64 ? IMAGE_FILE_MACHINE_AMD64 : IMAGE_FILE_MACHINE_I386 ;
685665 header.NumberOfSections = scnhdr_cnt;
686- header.TimeDateStamp = f_timedat;
666+ header.TimeDateStamp = cast ( uint ) f_timedat;
687667 static immutable ubyte [16 ] uuid =
688668 [ ' \xc7 ' , ' \xa1 ' , ' \xba ' , ' \xd1 ' , ' \xee ' , ' \xba ' , ' \xa9 ' , ' \x4b ' ,
689669 ' \xaf ' , ' \x20 ' , ' \xfa ' , ' \xf6 ' , ' \x6a ' , ' \xa4 ' , ' \xdc ' , ' \xb8 ' ];
@@ -700,7 +680,7 @@ void MsCoffObj_term(const(char)[] objfilename)
700680 {
701681 header_old.Machine = I64 ? IMAGE_FILE_MACHINE_AMD64 : IMAGE_FILE_MACHINE_I386 ;
702682 header_old.NumberOfSections = cast (ushort )scnhdr_cnt;
703- header_old.TimeDateStamp = f_timedat;
683+ header_old.TimeDateStamp = cast ( uint ) f_timedat;
704684 header_old.SizeOfOptionalHeader = 0 ;
705685 header_old.Characteristics = 0 ;
706686 foffset = (header_old).sizeof; // start after header
0 commit comments