Binary Reproducibility in Visual C++

前端 未结 2 510
遥遥无期
遥遥无期 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.

提交回复
热议问题