Skip to content

rustc produces indeterministic asm #57041

Closed
@bmwiedemann

Description

@bmwiedemann

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:

git clone https://github.com/bmwiedemann/git2-rs
cd git2-rs
git checkout race
./build.sh
for i in $(seq 20) ; do ./build.sh ; done | sort | uniq -c

Actual Result:

  8 26e2151e7f3593339976a02365fb0608  lib.s
 12 ad32d7431b7c1edb363d1f3238a3d0f5  lib.s

Expected Result:
rustc should always produce the same asm output

--- lib.s	2018-12-21 15:18:39.671245106 +0100
+++ lib.s-20181221	2018-12-21 15:18:28.115357401 +0100
@@ -450,8 +450,9 @@
 	movaps	%xmm1, _ZN3lib5panic10LAST_ERROR7__getit5__KEY17h3776bf008a82988eE@DTPOFF+16(%rax)
 	movl	$1, %ecx
 	movq	%rcx, %xmm1
-	cmpq	$0, _ZN3lib5panic10LAST_ERROR7__getit5__KEY17h3776bf008a82988eE@DTPOFF(%rax)
+	movq	_ZN3lib5panic10LAST_ERROR7__getit5__KEY17h3776bf008a82988eE@DTPOFF(%rax), %rcx
 	movdqa	%xmm1, _ZN3lib5panic10LAST_ERROR7__getit5__KEY17h3776bf008a82988eE@DTPOFF(%rax)
+	testq	%rcx, %rcx
 	je	.LBB14_9
 	movq	%xmm0, %r14
 	testq	%r14, %r14

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationA-reproducibilityArea: Reproducible / deterministic buildsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions