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

Object file in /tmp produces non-deterministic builds on Windows for crate-type=bin #112587

Open
danakj opened this issue Jun 13, 2023 · 7 comments
Assignees
Labels
A-reproducibility Area: Reproducible / deterministic builds C-bug Category: This is a bug. O-windows-msvc Toolchain: MSVC, Operating system: Windows

Comments

@danakj
Copy link
Contributor

danakj commented Jun 13, 2023

When building a --crate-type=bin target with rustc, an object file is produced in /tmp/<randomname> and that absolute path is then passed to the linker.

Windows puts paths to all object files in the PDB file, so this results in non-deterministic Windows builds (see #88982 (comment)). To be deterministic all paths must be relative paths, or fixed paths.

To resolve this, we could:

  1. Grow a command line to specify the path to the object file that rustc should write, and then pass to the linker.
  2. Grow a command line to specify the temp root (replacing /tmp or similar when specified), allowing it to be specified relative to the CWD. Then ensure -Zremap-cwd-prefix gets applied to it in order to produce a relative path.
  3. Other??

(FWIW I am cross-compiling Linux to Windows here which is why you see /tmp in the path :) But same things occur building on Windows.)

@danakj danakj added the C-bug Category: This is a bug. label Jun 13, 2023
@danakj
Copy link
Contributor Author

danakj commented Jun 13, 2023

cc: @michaelwoerister

@bjorn3
Copy link
Member

bjorn3 commented Jun 13, 2023

One option would be to move the object file(s) that currently end up in /tmp to be next to the output like we already do for codegen units.

@danakj
Copy link
Contributor Author

danakj commented Jun 13, 2023

Would you have any pointers to the code that does this for codegen units?

@bjorn3
Copy link
Member

bjorn3 commented Jun 13, 2023

let object = emit_obj.then(|| outputs.temp_path(OutputType::Object, Some(&self.name)));

and the code that emits the object file in /tmp is

let path = tmpdir.join("symbols.o");
I believe.

@bjorn3
Copy link
Member

bjorn3 commented Jun 13, 2023

@rustbot label +A-reproducibility +O-windows-msvc

(@danakj if you find other reproducability issues feel free to use this command to add the right label. most labels can be set by everyone.)

@rustbot rustbot added A-reproducibility Area: Reproducible / deterministic builds O-windows-msvc Toolchain: MSVC, Operating system: Windows labels Jun 13, 2023
@michaelwoerister
Copy link
Member

Yes, that should be fixable the way @bjorn3 suggests. I can't think of a reason why an object file would need to be in /tmp.

I'll assign the issue to me. @danakj, let me know if you plan to look into a fix.

@michaelwoerister michaelwoerister self-assigned this Jun 14, 2023
aarongable pushed a commit to chromium/chromium that referenced this issue Jun 16, 2023
This is done with a TODO while we work upstream to fix Rust-link-driven
Windows exe non-determinism issues. Upstream does intend to have
Rust able to produce deterministic results and there were already
tests for this that were disabled on Windows due to the reasons
being unclear which have now become clear thanks to our determinism
bots!

Upstream issues:
rust-lang/rust#112586
rust-lang/rust#112587

Bug: 1453509
Change-Id: I582e46792934d44866a45d9b57b2c7b64b52a2e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4618949
Reviewed-by: Erik Chen <[email protected]>
Commit-Queue: danakj <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1158781}
@bjorn3
Copy link
Member

bjorn3 commented Jun 19, 2023

cc #71714 which has the same cause.

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. O-windows-msvc Toolchain: MSVC, Operating system: Windows
Projects
None yet
Development

No branches or pull requests

4 participants