Skip to content
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

building the std for aarch64_be-unknown-linux-gnu_ilp32 twice in a row, the binary libcompiler_builtins.rlib is inconsistent #119372

Closed
lxy19980601 opened this issue Dec 28, 2023 · 5 comments
Labels
A-reproducibility Area: Reproducible / deterministic builds C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lxy19980601
Copy link
Contributor

We have experimented with recent versions of rust(from 2023-10-30 to 2023-12-27).
use RUSTC_BOOTSTRAP=1 cargo build --target aarch64_be-unknown-linux-gnu_ilp32 -Z build-std
It has been found that the 2023-11-05 version has binary inconsistencies in libcompiler_builtins.rmeta, and the 11-06 version is completely consistent. So th problem is fixed on 11-05. And I also found that 11-05 uses compiler_builtins v0.1.101, but 11-06 uses compiler_builtins v0.1.103.
I replaced the compiler_builtins version in rust-2023-11-05 from v0.1.101 to v0.1.103, and then found libcompiler_builtins.rmeta is consistent.

@lxy19980601 lxy19980601 added the C-bug Category: This is a bug. label Dec 28, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 28, 2023
@lxy19980601
Copy link
Contributor Author

Maybe some changes of crate compiler_builtin from version v0.1.101 to version v0.1.103 caused this problem.

@petrochenkov petrochenkov added the A-reproducibility Area: Reproducible / deterministic builds label Dec 28, 2023
@Noratrieb Noratrieb added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 28, 2023
@bjorn3
Copy link
Member

bjorn3 commented Dec 31, 2023

If I understand you correctly this issue has been fixed already since compiler-builtins 0.1.103. rust-lang/compiler-builtins#549 was probably the fix. Given that this has been fixed already, can this issue be closed?

@aerions
Copy link

aerions commented Jan 2, 2024

I guess I need to add more context to clarify more about our issue. The beginning of the event is that, when building rust std for target aarch64_be-unknown-linux-gnu_ilp32, most rlib exhibit binary inconsistencies, including the libstd so itself. After some investigation, it comes accross that the main issue was hash difference for compiler_builtins between two build.
rust-lang/compiler-builtins#549 did fix the problem. However, at the end of the day, I assume rust should ensure the compile result to be consistent between different builds when using the same enviroment+source code right?

Maybe there could be some verification setup for binary comparison? For example, ci running every week or monthly check on those issue

@bjorn3
Copy link
Member

bjorn3 commented Jan 2, 2024

Compiler builtins itself was giving a nondeterministic output of it's build script, which caused libcompiler_builtins.rlib to change and as a result everything that depends on it to change too. The build script of compiler builtins has been fixed in 0.1.103.

There is not much we can do about non-deterministic build scripts and proc macros. They are not sandboxed and may intentionally depend on the environment. For example they could be reading C header files from the system to produce bindings (eg because the target doesn't have a stable ABI) or read from a database. Optional sandboxing of proc macros by compiling them to wasm has been concidered, but for build scripts sandboxing is guaranteed to break things as one of the main reasons they exist is to invoke an external C compiler. And even with sandboxing there can be sources of non-determinism through for example multithreading inside build scripts. (or even deliberate random number generation)

@davidtwco
Copy link
Member

I'm going to close this as there's nothing for us to do - the binary inconsistency described in this issue has been resolved. rust-lang/compiler-builtins#549 fixed the issue by changing from a HashMap to a BTreeMap in compiler-builtins' build.rs (HashMap doesn't guarantee an iteration order, which meant that a generated source file would change each build for no reason).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-reproducibility Area: Reproducible / deterministic builds C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants