Skip to content

Toolchain paths are being compiled into binaires #116948

Open
@abrisco

Description

@abrisco

I noticed binaries produced by different users on the same machine resulting in binaries that were not byte-for-byte identical even though it was expected. Upon investigation, I found that absolute paths of components in the toolchain were being written into the binaries.

I created a new project hostpaths with cargo init hostpaths and added the following .cargo/config.toml file

[build]
rustflags = [
    "--remap-path-prefix=/Users/andrebrisco/Code/hostpaths=.",  # source code path
    "--remap-path-prefix=/Users/andrebrisco/.rustup=."  # toolchain path
]

I tried this code on a macOS machine:

fn main() {
    println!("Hello, world!");
}

Then I ran xxd on the compiled binary (xxd target/debug/hostpaths) and in the output see sections with the paths I was trying to strip

00070450: 2f55 7365 7273 2f72 756e 6e65 722f 2e63  /Users/runner/.c
00070460: 6172 676f 2f72 6567 6973 7472 792f 7372  argo/registry/sr
00070470: 632f 696e 6465 782e 6372 6174 6573 2e69  c/index.crates.i
00070480: 6f2d 3666 3137 6432 3262 6261 3135 3030  o-6f17d22bba1500
00070490: 3166 2f6d 656d 6368 722d 322e 352e 302f  1f/memchr-2.5.0/
000704a0: 7372 632f 6c69 622e 7273 2f40 2f00 6d65  src/lib.rs/@/.me
000704b0: 6d63 6872 2e31 3861 6563 3564 6635 3863  mchr.18aec5df58c
000704c0: 3636 6666 392d 6367 752e 3000 2f55 7365  66ff9-cgu.0./Use
000704d0: 7273 2f61 6e64 7265 6272 6973 636f 2f2e  rs/andrebrisco/.    <- unexpected
000704e0: 7275 7374 7570 2f74 6f6f 6c63 6861 696e  rustup/toolchain
000704f0: 732f 7374 6162 6c65 2d61 6172 6368 3634  s/stable-aarch64
00070500: 2d61 7070 6c65 2d64 6172 7769 6e2f 6c69  -apple-darwin/li
00070510: 622f 7275 7374 6c69 622f 6161 7263 6836  b/rustlib/aarch6
00070520: 342d 6170 706c 652d 6461 7277 696e 2f6c  4-apple-darwin/l
00070530: 6962 2f6c 6962 6d65 6d63 6872 2d64 6261  ib/libmemchr-dba
00070540: 3538 3861 3139 6337 3363 3761 662e 726c  588a19c73c7af.rl
00070550: 6962 286d 656d 6368 722d 6462 6135 3838  ib(memchr-dba588
00070560: 6131 3963 3733 6337 6166 2e6d 656d 6368  a19c73c7af.memch
00070570: 722e 3138 6165 6335 6466 3538 6336 3666  r.18aec5df58c66f
00070580: 6639 2d63 6775 2e30 2e72 6367 752e 6f29  f9-cgu.0.rcgu.o)
00070590: 002f 5573 6572 732f 7275 6e6e 6572 2f2e  ./Users/runner/.
000705a0: 6361 7267 6f2f 7265 6769 7374 7279 2f73  cargo/registry/s
000705b0: 7263 2f69 6e64 6578 2e63 7261 7465 732e  rc/index.crates.
000705c0: 696f 2d36 6631 3764 3232 6262 6131 3530  io-6f17d22bba150
000705d0: 3031 662f 7275 7374 632d 6465 6d61 6e67  01f/rustc-demang
000705e0: 6c65 2d30 2e31 2e32 332f 7372 632f 6c69  le-0.1.23/src/li
000705f0: 622e 7273 2f40 2f00 7275 7374 635f 6465  b.rs/@/.rustc_de
00070600: 6d61 6e67 6c65 2e37 6234 3934 3230 3239  mangle.7b4942029
00070610: 6635 3165 3235 372d 6367 752e 3000 2f55  f51e257-cgu.0./U
00070620: 7365 7273 2f61 6e64 7265 6272 6973 636f  sers/andrebrisco    <- unexpected
00070630: 2f2e 7275 7374 7570 2f74 6f6f 6c63 6861  /.rustup/toolcha
00070640: 696e 732f 7374 6162 6c65 2d61 6172 6368  ins/stable-aarch
00070650: 3634 2d61 7070 6c65 2d64 6172 7769 6e2f  64-apple-darwin/
00070660: 6c69 622f 7275 7374 6c69 622f 6161 7263  lib/rustlib/aarc
00070670: 6836 342d 6170 706c 652d 6461 7277 696e  h64-apple-darwin
00070680: 2f6c 6962 2f6c 6962 7275 7374 635f 6465  /lib/librustc_de
00070690: 6d61 6e67 6c65 2d36 3066 3164 3461 3430  mangle-60f1d4a40
000706a0: 3262 6165 3438 382e 726c 6962 2872 7573  2bae488.rlib(rus
000706b0: 7463 5f64 656d 616e 676c 652d 3630 6631  tc_demangle-60f1
000706c0: 6434 6134 3032 6261 6534 3838 2e72 7573  d4a402bae488.rus
000706d0: 7463 5f64 656d 616e 676c 652e 3762 3439  tc_demangle.7b49
000706e0: 3432 3032 3966 3531 6532 3537 2d63 6775  42029f51e257-cgu
000706f0: 2e30 2e72 6367 752e 6f29 002f 5573 6572  .0.rcgu.o)./User
00070700: 732f 7275 6e6e 6572 2f2e 6361 7267 6f2f  s/runner/.cargo/
00070710: 7265 6769 7374 7279 2f73 7263 2f69 6e64  registry/src/ind
00070720: 6578 2e63 7261 7465 732e 696f 2d36 6631  ex.crates.io-6f1

The expectation based on the use of --remap-path-prefix is that I would not see any references to andrebrisco in the binary at all.

Meta

rustc --version --verbose:

rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: aarch64-apple-darwin
release: 1.72.0
LLVM version: 16.0.5

rustc +nightly --version --verbose

rustc 1.74.0-nightly (249595b75 2023-08-23)
binary: rustc
commit-hash: 249595b7523fc07a99c1adee90b1947739ca0e5b
commit-date: 2023-08-23
host: aarch64-apple-darwin
release: 1.74.0-nightly
LLVM version: 17.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-reproducibilityArea: Reproducible / deterministic buildsC-bugCategory: This is a bug.O-macosOperating system: macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions