Windows, C++: investigate '/experimental:deterministic' compiler flag
See original GitHub issueFeature requests: what underlying problem are you trying to solve with this feature?
Investigate MSVC’s /experimental:deterministic
flag’s effect, maybe use it in MSVC crosstool. (Maybe put it behind a Bazel experimental flag.)
Motivation: to make C++ builds deterministic. For example, MSVC doesn’t support overriding non-deterministic macros like __DATE__
, maybe this flag solves that problem.
What operating system are you running Bazel on?
Windows 10
What’s the output of bazel info release
?
release 0.29.1
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
An introduction to deterministic builds with C/C++ - Conan Blog
Microsoft Visual Studio has a linker flag /Brepro that is undocumented by Microsoft. That flag sets the timestamps from the Portable Executable ...
Read more >changing pdb source file paths with /experimental ...
Go back to VisualStudio and add a Linker flag to your project: /experimental:deterministic /pathmap:<absolute path to .cpp, excluding filename>=C:\FooBar.
Read more >Optimize Options (Using the GNU Compiler Collection (GCC))
Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly...
Read more >Compiler Options Listed by Category - Microsoft Learn
Reference listing by category of the Microsoft C/C++ compiler ... Experimental options; Deprecated and removed compiler options; See also.
Read more >Two Deterministic Build Bugs | Random ASCII - WordPress.com
One was in Chromium, and the other was in Microsoft Windows. ... are deterministic I knew that the new build flag had to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Some other maybe interesting links:
I’ve been playing around with some trial and error and found that:
d1nodatetime
: undefs__DATE__
,__TIME__
,__TIMESTAMP__
. user may redefine them.Brepro
(should be supplied to all of cl, lib, and link): impliesd1nodatetime
and sets initial value of those#defines
equal to 1. Additionally modifies some data stored in object files to make them binary-identical between builds.experimental:deterministic
impliesBrepro
and issues a warning if problematic code is found (usage of__TIME__
, etc.)Using
Brepro
,INCREMENTAL:NO
, andZ7
, I’m able to get outputs to be binary-identical between builds on the same computer, with some exceptions: If a .manifest and/or resource file (.rc) is processed during compilation/linking, it creates a temporary file during processing, and for whatever reason, this temporary path is included in the resulting pdb (obviously the temporary has been deleted by the time the build is done, so…pointless). This can be “solved” by just omitting the .rc or using a side-by-side .manifest instead of embedding it. However, pdbs with these different temporary paths inside are completely interchangeable - the difference does not prevent a debugger loading it for example.d1trimfile:<path[=ENV_VAR]>
(seen in above links) sounds like it was originally intended to trim the__FILE__
definition, which it does seem to do in my testing (handy if you useFC
, I guess). As discussed in above links, they seem to have made it apply to paths stored in .obj files referencing a pdb as well, which occurs on non-Z7
builds, i.e.Zi
builds. Unfortunately my quick test still shows full pdb path being in the eventual exe file.However…why is this a problem? The differences in the pdb can be seen to be inconsequential and the exe will be identical apart from the pdb path, which is accounted for by existing tools (like debuggers and
symsrv
, which dont use a path to index the pdb).Maybe make a request to msvc team to have
d1trimfile
also apply to the pdb path stored in exe? Since they recently made a related change perhaps it just needs to be asked for.I got
/pdbaltpath:%_PDB%
working in a toolchain file:I still have some trouble fitting
/d1trimfile
into the toolchain file.