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

rustc-driver binary is not identical for every build #102299

Closed
sundeep-kokkonda opened this issue Sep 26, 2022 · 7 comments
Closed

rustc-driver binary is not identical for every build #102299

sundeep-kokkonda opened this issue Sep 26, 2022 · 7 comments

Comments

@sundeep-kokkonda
Copy link
Contributor

The rust build output [[build-dir]]/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-67046b4f71f47f00.so is not identical for every build. I debugged the issue by comparing all the generated object files between two different builds, the object file '[[build-dir]]/bootstrap/debug/incremental/bootstrap-22qjf7qknjduo/s-gdrx5ab0wu-1spyacv-3unuz3kev23rs/4oqq7pii1co5y8sx.o' is different between two builds. This object file .rodata section is holding the filename with path, and when the path is changed this section is getting chaged and causing final .so file to be changed.

Below is the contents of .rodata section from two build directories.

.rodata section in build directory : build-1
:~/rust/build-1$ objdump -s -j .rodata..L__unnamed_34 ~/rust/build-1/bootstrap/debug/incremental/bootstrap-22qjf7qknjduo/s-gdrx5ab0wu-1spyacv-3unuz3kev23rs/4oqq7pii1co5y8sx.o

/home/skokkonda/rust/build-1/bootstrap/debug/incremental/bootstrap-22qjf7qknjduo/s-gdrx5ab0wu-1spyacv-3unuz3kev23rs/4oqq7pii1co5y8sx.o: file format elf64-x86-64

Contents of section .rodata..L__unnamed_34:
0000 2f686f6d 652f736b 6f6b6b6f 6e64612f /home/skokkonda/
0010 72757374 2f627569 6c642d31 2f783836 rust/build-1/x86
0020 5f36342d 756e6b6e 6f776e2d 6c696e75 _64-unknown-linu
0030 782d676e 752f7374 61676530 2f62696e x-gnu/stage0/bin
0040 2f727573 7463 /rustc

.rodata section in build directory : build-test
:~/rust/build-1$ objdump -s -j .rodata..L__unnamed_34 ~/rust/build-test/bootstrap/debug/incremental/bootstrap-22qjf7qknjduo/s-gds2uitpgl-fm0ssi-193tjef7tbwwd/4oqq7pii1co5y8sx.o

/home/skokkonda/rust/build-test/bootstrap/debug/incremental/bootstrap-22qjf7qknjduo/s-gds2uitpgl-fm0ssi-193tjef7tbwwd/4oqq7pii1co5y8sx.o: file format elf64-x86-64

Contents of section .rodata..L__unnamed_34:
0000 2f686f6d 652f736b 6f6b6b6f 6e64612f /home/skokkonda/
0010 72757374 2f627569 6c642d74 6573742f rust/build-test/
0020 7838365f 36342d75 6e6b6e6f 776e2d6c x86_64-unknown-l
0030 696e7578 2d676e75 2f737461 6765302f inux-gnu/stage0/
0040 62696e2f 72757374 63 bin/rustc

I tried two different builds with identical build path and then compared the binaries, those are identical.

This issue is causing a automated test failure in Yocto build enevironment. Can anyone confirm that is it a bug in rust?

@Foorack
Copy link

Foorack commented Oct 7, 2022

I noticed the path-name contains /incremental/. Is this also an issue when incremental compilation is off?

@sundeep-kokkonda
Copy link
Contributor Author

sundeep-kokkonda commented Oct 10, 2022

The 'incremental' path is autogenerated in build directory, this object file is generated during the 'stage-0' and still 'stage-1' is yet to build, so I guess in that way the build is 'incremental'? Is there any option that can avoid this?

@faptc

This comment was marked as resolved.

@rustbot rustbot added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) A-reproducibility Area: Reproducible / Deterministic builds T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 10, 2022
@kpcyrd
Copy link

kpcyrd commented Oct 10, 2022

I think it's specifically the build path that's embedded, this is a known limitation at the moment and projects like Arch Linux that are currently doing reproducible builds use a standardized build path to reproduce their rust binaries (and the rust compiler itself).

It would be nice to have rust/cargo not embed the build path by default (that's why I've filed rust-lang/cargo#5505) but it doesn't block the security advantages of reproducible builds.

@sundeep-kokkonda
Copy link
Contributor Author

@kpcyrd Thanks for the info... Is there a way available to eliminate build paths in final binary? I tried a few ways with --remap-path-prefix & -Z binary-dep-depinfo options but still the path info is present in final binary and which makes builds are not reproducible.
Let me know if you know any option/change in code removes the path in final binary, so that I can make my local patch...

@kpcyrd
Copy link

kpcyrd commented Oct 17, 2022

This has worked for me in the past:

RUSTFLAGS="--remap-path-prefix=$HOME=/remap-home --remap-path-prefix=$PWD=/remap-pwd" cargo build --release --verbose

I had a CI job in place that uses reprotest like this: https://github.com/kpcyrd/sniffglue/blob/main/ci/reprotest.sh

@jyn514
Copy link
Member

jyn514 commented Nov 5, 2022

It sounds like this is avoidable using --remap-path-prefix, so I'm going to close this issue.

The issue tracker is not a support forum. For future questions please ask in one of these places:

https://discord.gg/rust-lang/
https://discord.gg/rust-lang-community/
https://users.rust-lang.org/
https://rust-lang.zulipchat.com/

@jyn514 jyn514 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2022
LeanderBB pushed a commit to LeanderBB/you-have-mail that referenced this issue May 21, 2023
Rustc still does not have complete support for fully reproducible builds
(rust-lang/rust#75362). Attempt to narrow the
gap by following the advice from
(rust-lang/rust#102299) and overwrite all
panic paths with a different, consistent value.
LeanderBB pushed a commit to LeanderBB/you-have-mail that referenced this issue May 21, 2023
Rustc still does not have complete support for fully reproducible builds
(rust-lang/rust#75362). Attempt to narrow the
gap by following the advice from
(rust-lang/rust#102299) and overwrite all
panic paths with a different, consistent value.
LeanderBB pushed a commit to LeanderBB/you-have-mail that referenced this issue May 21, 2023
Rustc still does not have complete support for fully reproducible builds
(rust-lang/rust#75362). Attempt to narrow the
gap by following the advice from
(rust-lang/rust#102299) and overwrite all
panic paths with a different, consistent value.
LeanderBB pushed a commit to LeanderBB/you-have-mail that referenced this issue May 21, 2023
Rustc still does not have complete support for fully reproducible builds
(rust-lang/rust#75362). Attempt to narrow the
gap by following the advice from
(rust-lang/rust#102299) and overwrite all
panic paths with a different, consistent value.
LeanderBB pushed a commit to LeanderBB/you-have-mail that referenced this issue May 22, 2023
Rustc still does not have complete support for fully reproducible builds
(rust-lang/rust#75362). Attempt to narrow the
gap by following the advice from
(rust-lang/rust#102299) and overwrite all
panic paths with a different, consistent value.

Changes:

* Use --remap-path-prefixes to make paths consistent.
* Set build path to /tmp/build-yhm.
* Include Cargo.lock files to compile the same dependencies.
LeanderBB pushed a commit to LeanderBB/you-have-mail that referenced this issue May 22, 2023
Rustc still does not have complete support for fully reproducible builds
(rust-lang/rust#75362). Attempt to narrow the
gap by following the advice from
(rust-lang/rust#102299) and overwrite all
panic paths with a different, consistent value.

Changes:

* Use --remap-path-prefixes to make paths consistent.
* Set build path to /tmp/build-yhm.
* Include Cargo.lock files to compile the same dependencies.
LeanderBB pushed a commit to LeanderBB/you-have-mail that referenced this issue May 22, 2023
Rustc still does not have complete support for fully reproducible builds
(rust-lang/rust#75362). Attempt to narrow the
gap by following the advice from
(rust-lang/rust#102299) and overwrite all
panic paths with a different, consistent value.

Changes:

* Use --remap-path-prefixes to make paths consistent.
* Set build path to /tmp/build-yhm.
* Include Cargo.lock files to compile the same dependencies.
LeanderBB pushed a commit to LeanderBB/you-have-mail that referenced this issue May 22, 2023
Rustc still does not have complete support for fully reproducible builds
(rust-lang/rust#75362). Attempt to narrow the
gap by following the advice from
(rust-lang/rust#102299) and overwrite all
panic paths with a different, consistent value.

Changes:

* Use --remap-path-prefixes to make paths consistent.
* Set build path to /tmp/build-yhm.
* Include Cargo.lock files to compile the same dependencies.
@jieyouxu jieyouxu removed A-reproducibility Area: Reproducible / Deterministic builds C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants