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

Windows hard-linked executables are modified in place #8348

Closed
rogday opened this issue Jun 9, 2020 · 1 comment · Fixed by #11122
Closed

Windows hard-linked executables are modified in place #8348

rogday opened this issue Jun 9, 2020 · 1 comment · Fixed by #11122
Labels
C-bug Category: bug O-windows OS: Windows

Comments

@rogday
Copy link

rogday commented Jun 9, 2020

Problem

As the title says, cargo overrides all executables in a build folder. Expected behavior: don't override unrelated executables.

Steps

  1. Write any program and run 'cargo build/run [--release]'.
  2. Locate compiled binary(assume its foo.exe) and calculate its checksum.
  3. Rename the executable to something different(assume bar.exe).
  4. Change your program a little bit to differentiate resulting binary and compile again.
  5. Compare checksums of foo.exe and bar.exe - they are the same.

Notes

It doesn't work with third-party binary.

Output of cargo version:

cargo 1.45.0-nightly (9fcb8c1 2020-05-25)

@rogday rogday added the C-bug Category: bug label Jun 9, 2020
@ehuss
Copy link
Contributor

ehuss commented Jun 9, 2020

This is a consequence of Cargo using a hard link from the actual executable (in the deps directory) and the one in the output directory (target/debug). On Windows, I believe link.exe does not remove the executable, but instead truncates and modifies it. When you rename the executable, the hard link is preserved, so the modifications made by the linker show up in all hard-linked copies.

It might be possible to unlink the executable before running the build. I'm uncertain what the consequences of that would be.

@ehuss ehuss changed the title Cargo overrides all executables in a build folder Windows hard-linked executables are modified in place Jun 9, 2020
@ehuss ehuss added the O-windows OS: Windows label Jun 9, 2020
weihanglo added a commit to weihanglo/cargo that referenced this issue Sep 21, 2022
Some linkers do not remove the executable, but truncate and modify it.
That results in the old hard-link being modified even after renamed.
We delete the old artifact here to prevent this behavior from confusing users.
See rust-lang#8348.
weihanglo added a commit to weihanglo/cargo that referenced this issue Sep 21, 2022
Some linkers do not remove the executable, but truncate and modify it.
That results in the old hard-link being modified even after renamed.
We delete the old artifact here to prevent this behavior from confusing users.
See rust-lang#8348.
weihanglo added a commit to weihanglo/cargo that referenced this issue Sep 21, 2022
Some linkers do not remove the executable, but truncate and modify it.
That results in the old hard-link being modified even after renamed.
We delete the old artifact here to prevent this behavior from confusing users.
See rust-lang#8348.
weihanglo added a commit to weihanglo/cargo that referenced this issue Sep 21, 2022
Some linkers do not remove the executable, but truncate and modify it.
That results in the old hard-link being modified even after renamed.
We delete the old artifact here to prevent this behavior from confusing users.
See rust-lang#8348.
weihanglo added a commit to weihanglo/cargo that referenced this issue Sep 21, 2022
Some linkers do not remove the executable, but truncate and modify it.
That results in the old hard-link being modified even after renamed.
We delete the old artifact here to prevent this behavior from confusing users.
See rust-lang#8348.
weihanglo added a commit to weihanglo/cargo that referenced this issue Sep 21, 2022
Some linkers do not remove the executable, but truncate and modify it.
That results in the old hard-link being modified even after renamed.
We delete the old artifact here to prevent this behavior from confusing users.
See rust-lang#8348.
weihanglo added a commit to weihanglo/cargo that referenced this issue Sep 21, 2022
Some linkers do not remove the executable, but truncate and modify it.
That results in the old hard-link being modified even after renamed.
We delete the old artifact here to prevent this behavior from confusing users.
See rust-lang#8348.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug O-windows OS: Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants