Skip to content

Cargo modifies renamed executable in the target directory on rebuild #11101

Closed
@Veetaha

Description

@Veetaha

Problem

If you rename the executable output file in target/{profile} and rebuild the project, then the renamed file is modified to be a copy of the new binary output.

I suppose it is possible to create an unlimited amount of renamed files this way and all of them will be modified to be the copy of the latest built executable. I've verified that renaming the executable and building the project two times (i.e. having original executable, renamed_copy_1, renamed_copy_2).

Steps

The commands in terminal (bash). I've copied them with the output lower

~/junk $ cargo new rename-repro
     Created binary (application) `rename-repro` package
~/junk $ cd rename-repro
~/junk/rename-repro (master) $ cargo build
   Compiling rename-repro v0.1.0 (/home/veetaha/junk/rename-repro)
    Finished dev [unoptimized + debuginfo] target(s) in 0.39s
~/junk/rename-repro (master) $ ls -lh ./target/debug
total 3.8M
drwxrwxr-x 2 veetaha veetaha 4.0K Sep 17 18:13 build
drwxrwxr-x 2 veetaha veetaha 4.0K Sep 17 18:13 deps
drwxrwxr-x 2 veetaha veetaha 4.0K Sep 17 18:13 examples
drwxrwxr-x 3 veetaha veetaha 4.0K Sep 17 18:13 incremental
-rwxrwxr-x 2 veetaha veetaha 3.8M Sep 17 18:13 rename-repro
-rw-rw-r-- 1 veetaha veetaha  103 Sep 17 18:13 rename-repro.d
~/junk/rename-repro (master) $ mv ./target/debug/rename-repro ./target/debug/renamed-1
~/junk/rename-repro (master) $ echo "static FOO: [u8; 10000000] = [1; 10000000]; fn main() { dbg!(FOO); }" > src/main.rs
~/junk/rename-repro (master) $ cargo build
   Compiling rename-repro v0.1.0 (/home/veetaha/junk/rename-repro)
    Finished dev [unoptimized + debuginfo] target(s) in 0.33s
~/junk/rename-repro (master) $ ls -lh ./target/debug
total 27M
drwxrwxr-x 2 veetaha veetaha 4.0K Sep 17 18:13 build
drwxrwxr-x 2 veetaha veetaha 4.0K Sep 17 18:13 deps
drwxrwxr-x 2 veetaha veetaha 4.0K Sep 17 18:13 examples
drwxrwxr-x 3 veetaha veetaha 4.0K Sep 17 18:13 incremental
-rwxrwxr-x 3 veetaha veetaha  14M Sep 17 18:13 renamed-1
-rwxrwxr-x 3 veetaha veetaha  14M Sep 17 18:13 rename-repro
-rw-rw-r-- 1 veetaha veetaha  103 Sep 17 18:13 rename-repro.d

As you can notice, the size of the file renamed-1 changed to 14M, where it was 3.8M before, and it do is the copy of that latest build (rename-repro)

Here is also the reproduction on windows recorded in a video

rust-rename-repro.mp4

Notes

Verified that the bug reproduces both on Linux amd64 and Windows amd64

Version

cargo 1.63.0 (fd9c4297c 2022-07-01)
release: 1.63.0
commit-hash: fd9c4297ccbee36d39e9a79067edab0b614edb5a
commit-date: 2022-07-01
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1n)
os: Ubuntu 20.04 (focal) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layoutArea: target output directory layout, naming, and organizationC-bugCategory: bugO-linuxOS: LinuxO-windowsOS: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions