-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows, C++: investigate '/experimental:deterministic' compiler flag #9466
Comments
/cc @meteorcloudy @hlopko |
We have no experience so far. |
I found https://developercommunity.visualstudio.com/content/problem/502528/changing-pdb-source-file-paths-with-experimentalde.html which says: """PDBs are not deterministic and aren't the intended target of this feature, so there may still be a great many full paths still embedded in the PDBs after doing this. These switches are intended for object file and executable determinism, not PDBs.""" Since executables embed a ref to the PDB in /debug build, it looks like deterministic builds with debug information remain impossible with MSVC. (Plug: They are possible with clang-cl and lld-link, see http://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html for how.) |
Some other maybe interesting links:
I've been playing around with some trial and error and found that:
Using
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 Maybe make a request to msvc team to have |
(You can make the pdb path in the exe relative with |
@nico what exactly is `%_PDB%? Where it comes from? I wonder how to I change Bazel MSVC toolchain to use it? |
@konste: You put that there literally. See https://docs.microsoft.com/en-us/cpp/build/reference/pdbaltpath-use-alternate-pdb-path?view=msvc-160 |
I got
I still have some trouble fitting |
@dgrunwald did you get anywhere with /d1trimfile in the toolchain? |
No. |
@dgrunwald thanks. I've got this working:
The next problem we are facing is that Bazel's use of /Fo to control output location appears to cause msvc to write an absolute path into the object file. Utterly bizarre, but removing the /Fo and allowing msvc to write to current directory causes this behaviour to stop. Has anyone seen this? |
One more flag that can help: https://developercommunity.visualstudio.com/t/The-result-of-__FILE__-is-not-lower-case/1392988?q=associate+to+test+case
|
I was experimenting with this recently using MSVC 2022 (compiler version 19.36.32535) and here is what I found.
Also Next observation: .obj files for some reason include absolute path to themselves. I don't know why and what what to do with it. Also PDB files appear to be very different when produced on the different machines. So there is a progress, but not the final solution unfortunately. |
Great, information, thanks for sharing. This sounds very similar behaviour to VS2019. I am working around the d1trimfile issue in two ways: Approach 1) as mentioned above, write a clwrap.bat which figures out the trim directory and adds it to the command line, call clwrap.bat instead of cl.exe in the toolchain (we take a copy of Bazel's autogenerated toolchain and check it in to our codebase). Approach 1 worked fine and was simple, but confuses coverity's bazel integration. Coverity introspects the build and expects to see something called exactly "cl.exe" invoked. So we are now following Approach 2. @konste did you try a compile without /Fo? If so, does the absolute path disappear from obj? That is what I see. |
BuildXL uses subst to map out the current folder (build/src) into an stable one.
Then builds from B:\ - and paths are seeing as if coming from there. One can go even further (maybe) and split - say source code comes from a:, and buid is in b:, etc. |
On the other hand C# has /pathmap to remap one or more roots to another stable name, I guess C++ (MSVC) is just missing this.... |
I understand the idea of the compiler wrapper (cmd or exe), but it does not help because of the full path to object files inside object files. By the way how you handle obj files at execution root when you compile without /Fo?
Unfortunately both with and without /Fo I see absolute path in obj :-( It is very weird that we see different results here. Wonder if the difference is in the compiler version or some other options because /Fo does not seem to make a difference for me. |
Interestingly I found
which makes me believe that it could be supported to some degree, just badly undocumented anywhere. |
I've tried a simple reproducer, and I was using pathmap, and that does seem to be the key:
outputs:
Tested on:
Note: I am also using d1trimfile and Brepro, I recall they help in other scenarios. |
But we still need compiler wrapper script to set |
Yes |
Holy... didn't know this worked for C++ too! Thanks for exploring!!! |
BTW link.exe also have undocumented |
PDB is non-deterministic for us too. My hope is that as it is a leaf artifact this will not matter. Do you see it as being a practical issue in your deployment? |
Feature 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
The text was updated successfully, but these errors were encountered: