-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rustc produces indeterministic asm #57041
Comments
Spent some more time on this and did for i in $(seq 20) ; do
echo 10000 > /proc/sys/kernel/ns_last_pid
taskset 1 setarch `arch` -R strace -s 4096 -o rustc$i.strace -f ./build.sh
done This can create more reproducible results as long as the system is idle. diffing strace outputs showed that the 'idle' result correlated with more, smaller All this indicates that there is some raciness in the communication between the involved threads and this is where the non-determinism comes from. |
Have you found any difference in the emitted LLVM IR? |
@jonas-schievink no, LLVM IR is always deterministic, as mentioned in the last line of the original report. |
Because of my very limited rust-foo I would appreciate help in further reducing the 183 lines of .rs files into an even smaller reproducer so that it becomes more visible what matters in there. |
@bmwiedemann In that case, can you reproduce this by running
Does it make a difference if you pass (this does indeed look like the same problem as #50556) |
I changed my build.sh to have I also tried -Ccodegen-units=$N and 1 behaved pretty much like before but 2 produced 2 output files that did not seem to vary for some reason. I'm on llvm-5,0,1 atm. llvm-6.0.1 is also bad, but llc from llvm-7.0.0 seems to be good. |
I now ran my autoreduce script on lib.ll and shrank it to 176 lines: |
In llvm I ran a |
cc #34902 |
Is there anything actionable to do here on the side of rustc? Per your investigation this issue has already been fixed in LLVM 7.0. |
I think this can be closed, once someone checks the original reproduction with a nightly build. |
Found another patch that makes llc determistic with lib.ll from the full git-rs |
@bmwiedemann LLVM has short release cycles and LLVM 6 is long since dead. Not even LLVM 7 will receive further backports (there will only be one more release with a single change, that was not included in LLVM 7.0.1 because it is ABI breaking). |
We are now on LLVM 9, so this should be fixed since a long time. Not sure if it's effective to add a test for this though, so maybe we should just close? |
I think it would be good to verify that this is indeed fixed, i.e., that we no longer encounter problems here. Once that's done, we can definitely close. |
I ran commands from issue description few times with changes to ignore all warnings and I think the output looks right:
Increasing number of runs from 20 to 2000 still yields deterministic assembly. |
That example was minimized though to trigger one particular issue. I still experienced nondeterminism with some rust builds. E.g. in packages alacritty, bat, exa, rust, svgcleaner, tealdeer I can debug these separately and file new issues. |
This specific issues seems to be resolved but there are other problems like #34902 Ideally each bug should have it's own issue. |
Yep, closing this. Please file other issues if other nondeterminism arises. |
While working on reproducible builds for openSUSE, I found that
the svgcleaner and exa rust packages had variations in machine code.
For exa, I traced this down to variations from git2-rs that is embedded there.
From that I reduced the code as much as I could, so that now there are only 183 lines of rust left.
Steps to Reproduce:
Actual Result:
Expected Result:
rustc should always produce the same asm output
I have identified 6 places that can be dropped and make the output reproducible:
https://github.com/bmwiedemann/git2-rs/blob/race/src/panic.rs#L11
https://github.com/bmwiedemann/git2-rs/blob/race/src/lib.rs#L5
https://github.com/bmwiedemann/git2-rs/blob/race/src/lib.rs#L13 ++
https://github.com/bmwiedemann/git2-rs/blob/race/src/call.rs#L10 +4
https://github.com/bmwiedemann/git2-rs/blob/race/src/index.rs#L39 +8
https://github.com/bmwiedemann/git2-rs/blob/race/src/index.rs#L64 ++
This bug might be related to bug #50556, but that one is closed and this bug is still reproducible with rust-1.31
I checked that llvm-bc and llvm-ir output are reproducible even when asm is not.
The text was updated successfully, but these errors were encountered: