Skip to content

rust-lld on NixOS can't link the program if the target dir lives on a path with spaces in it #138513

Open
@TheAwesome98-Real

Description

@TheAwesome98-Real

Code

any code works, even that which doesn't link to c libraries. to reproduce it, you can try this:

mkdir -p "/tmp/test dir/testing"
cd "/tmp/test dir/testing"
cargo init
cargo build

i expected it to compile, but it said this:

   Compiling testing v0.1.0 (/tmp/test dir/testing)
error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/tmp/rustcucYSDn/symbols.o" "<7 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcucYSDn/raw-dylibs" "-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,-znostart-stop-gc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/tmp/test dir/testing/target/debug/deps/testing-a26199dce8a80c8e" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: cannot open dir/testing/target/debug/deps/testing-a26199dce8a80c8e: No such file or directory
          rust-lld: error: cannot open /tmp/test: No such file or directory
          rust-lld: error: cannot open dir/testing/target/debug/deps/testing-a26199dce8a80c8e.1f4zjopx4co8wg8v0m5gp177f.rcgu.o: No such file or directory
          rust-lld: error: cannot open /tmp/test: No such file or directory
          rust-lld: error: cannot open dir/testing/target/debug/deps/testing-a26199dce8a80c8e.6rob1l3zpd0lgrz2ghmpkidqj.rcgu.o: No such file or directory
          rust-lld: error: cannot open /tmp/test: No such file or directory
          rust-lld: error: cannot open dir/testing/target/debug/deps/testing-a26199dce8a80c8e.784v8tgyr5k5uima1n1d3z0mk.rcgu.o: No such file or directory
          rust-lld: error: cannot open /tmp/test: No such file or directory
          rust-lld: error: cannot open dir/testing/target/debug/deps/testing-a26199dce8a80c8e.883o2n7eztjk0o7arvymjht7i.rcgu.o: No such file or directory
          rust-lld: error: cannot open /tmp/test: No such file or directory
          rust-lld: error: cannot open dir/testing/target/debug/deps/testing-a26199dce8a80c8e.94740eyfkqulmvhrsi1fqyy0q.rcgu.o: No such file or directory
          rust-lld: error: cannot open /tmp/test: No such file or directory
          rust-lld: error: cannot open dir/testing/target/debug/deps/testing-a26199dce8a80c8e.apbnli2khxbnh4tqkgi8ctsp6.rcgu.o: No such file or directory
          rust-lld: error: cannot open /tmp/test: No such file or directory
          rust-lld: error: cannot open dir/testing/target/debug/deps/testing-a26199dce8a80c8e.budf0e3pu8uovxzzurmmql825.rcgu.o: No such file or directory
          collect2: error: ld returned 1 exit status


error: could not compile `testing` (bin "testing") due to 1 previous error

Version it worked on

according to the .comment section of one of my applications, it was rustc version 1.85.0-nightly (d4025ee45 2024-12-12), but this is not likely the latest version that successfully compiles it, as i hadn't updated rust in a while, as indicated by the last year build date in the version.

Version with regression

rustc --version --verbose:

rustc 1.87.0-nightly (cbfdf0b01 2025-03-13)
binary: rustc
commit-hash: cbfdf0b014cb04982a9cbeec1578001001167f6e
commit-date: 2025-03-13
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

the regression occurred between 2 nightly versions. i don't know what to do in that case

Metadata

Metadata

Assignees

Labels

A-linkageArea: linking into static, shared libraries and binariesC-external-bugCategory: issue that is caused by bugs in software beyond our controlO-NixOSOperating system: NixOS, https://nixos.org/T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions