Closed
Description
$ rustup run nightly rustc --version
rustc 1.27.0-nightly (428ea5f6b 2018-05-06)
$ rustup run nightly cargo --version
cargo 1.27.0-nightly (af3f1cd29 2018-05-03)
I had issues building a deterministic binary for one of my projects, this is the reprotest command I ran:
reprotest -vv --vary=-all --store-dir=artifacts/ --source-pattern 'Cargo.* src/' '
CARGO_HOME="'$HOME'/.cargo" RUSTUP_HOME='"$HOME/.rustup"' \
RUSTFLAGS="--remap-path-prefix=$HOME=/remap-home --remap-path-prefix=$PWD=/remap-pwd -Ccodegen-units=1" \
cargo +nightly build --release --verbose --locked' \
target/release/badtouch
by setting -Ccodegen-units=1
I could considerably reduce the size of the diffoscope output (let's ignore this for now), but the build was still non-deterministic, the root cause being 2/3 instructions:
First build
- c1f5f: 48 83 b8 e0 fd ff ff cmpq $0x0,-0x220(%rax)
- c1f66: 00
- c1f67: 66 0f 7f 80 e0 fd ff movdqa %xmm0,-0x220(%rax)
- c1f6e: ff
Second build
+ c1f5f: 48 8b 88 e0 fd ff ff mov -0x220(%rax),%rcx
+ c1f66: 66 0f 7f 80 e0 fd ff movdqa %xmm0,-0x220(%rax)
+ c1f6d: ff
+ c1f6e: 48 85 c9 test %rcx,%rcx
This causes a bunch of other differences since the first version is two bytes shorter.
I'm not sure if this decision is made by llvm or rustc, but it seems this happens in a non-deterministic way.
The project I'm using to test this is rather large, sadly I can't provide an isolated example. It also seems this doesn't affect every project.
Screenshot (easier to read)
cc: @infinity0