Binary Reproducibility in Visual C++

前端 未结 2 508
遥遥无期
遥遥无期 2021-01-12 23:28

Is there a way to force the same code to produce the same binary in Visual C++? Turn off the timestamp in the PE or force the timestamp in the PE to be some fixed value, in

相关标签:
2条回答
  • 2021-01-13 00:03

    It's not only a timestamp - there's an embedded GUID used for PDB matching - as John Robbins explains.

    Even beyond that, there's just no way to force the compiler to generate consistent results, as Jim Griesmer explains -

    compiler writers are far more interested in generating correctly functioning code and generating it quickly than ensuring that whatever is generated is laid out identically on your hard drive. Due to the numerous and varied methods and implementations for optimizing code, it is always possible that one build ended up with a little more time to do something extra or different than another build did. Thus, the final result could be a different set of bits for what is the same functionality.

    Thus, function and section order are not guaranteed to be consistently ordered in the resulting PE. An example is at the link.

    0 讨论(0)
  • 2021-01-13 00:08

    I suppose you could write a utility to open the PE, set the checksum to 0, set the timestamp to what you like, recompute the crc, then write it back out. It would be nice if there were an official way to ensure perfect binary reproducibility, though.

    For more information: http://msdn.microsoft.com/en-us/magazine/cc301805.aspx

    0 讨论(0)
提交回复
热议问题