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

Names of intermediate files collide when running rustc in parallel #10971

Closed
SiegeLord opened this issue Dec 15, 2013 · 12 comments · Fixed by #83846
Closed

Names of intermediate files collide when running rustc in parallel #10971

SiegeLord opened this issue Dec 15, 2013 · 12 comments · Fixed by #83846
Assignees
Labels
A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@SiegeLord
Copy link
Contributor

SiegeLord commented Dec 15, 2013

For example, given an empty lib.rs, this happens:

rustc --lib lib.rs & rustc --rlib lib.rs
error: linking with `cc` failed: exit code: 1
note: cc arguments: '-m64' '-L/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib' '-o' 'liblib-9ed81b85-0.0.so' 'lib.o' 'lib.metadata.o' '-Wl,--as-needed' '-L/tmp/.rust' '-L/tmp' '-L/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib' '-lstd-04ff901e-0.9-pre' '-lrt' '-ldl' '-lm' '-lpthread' '-lstdc++' '-shared' '-lmorestack' '-Wl,-rpath,$ORIGIN/../usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib' '-Wl,-rpath,/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib'
note: /usr/bin/ld: reopening lib.o: No such file or directory

/usr/bin/ld: final link failed: No such file or directory
collect2: error: ld returned 1 exit status

error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /home/siege/src/rust2/src/libsyntax/diagnostic.rs:102
task '<main>' failed at 'explicit failure', /home/siege/src/rust2/src/librustc/lib.rs:398

This could be fixed in two main ways.

  1. Add an option (e.g. --temps-path) to store the intermediates in a specific location
  2. Add some kind of hash to the names of the intermediates to stop them from colliding. Can't just be the pkgid hash, as it'd still fail the above test.
@metajack
Copy link
Contributor

This is sort of a duplicate of #10922.

Does these libraries have link metadata that isn't converted to pkgids?

@SiegeLord
Copy link
Contributor Author

lib.rs is an empty file, so there is no custom metadata.

@metajack
Copy link
Contributor

Then it's not really a dupe of that bug as this behavior existed before the change to pkgids.

One workaround would be to change crate name inference to use the something like the last component of the path of the dirname of the file if the file has one of hte well known names (lib.rs, test.rs, main.rs and bench.rs).

@SiegeLord
Copy link
Contributor Author

Well, note that this only affects the intermediate files. If I do this:

rustc --lib lib.rs && rustc --rlib lib.rs

I get the two files (liblib-9ed81b85-0.0.rlib and liblib-9ed81b85-0.0.so) as expected. I am perfectly content with the library names being what they are. The issue is that the intermediate files are named lib.o, lib.bc and so on, for both calls to rustc. Therefore, running them in parallel leads to a race condition. In C/C++ I would have done this:

gcc -fPIC -c lib.c -o lib_shared/lib.o & gcc -c lib.c -o lib_static/lib.o
...

In D, which has a similar situation as Rust, I'd have used the equivalent of the --temps-path idea:

ldc2 -relocation-model=pic --shared lib.d -od=shared_lib_objects & ldc2 --lib lib.d -od=static_lib_objects

Where -od does what --temps-path would do.

@steveklabnik
Copy link
Member

A lot has changed here, but with an empty lib.rs, I get

$ rustc --crate-type=rlib lib.rs & rustc --crate-type=staticlib lib.rs
[1] 5798
error: failed to remove lib.0.o: couldn't unlink path (no such file or directory (No such file or directory); path=lib.0.o)
error: aborting due to previous error

Which seems like a similar error.

@steveklabnik steveklabnik added the A-linkage Area: linking into static, shared libraries and binaries label Jan 23, 2015
@steveklabnik
Copy link
Member

Triage: a slightly different error today:

$ touch lib.rs
$ rustc --crate-type=rlib lib.rs & rustc --crate-type=staticlib lib.rs
[1] 17820
error: failed to build archive: No such file or directory
[1]+  Done                    rustc --crate-type=rlib lib.rs

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 20, 2017
@steveklabnik
Copy link
Member

Triage: apparently PowerShell doesn't make this easy, so I cannot attempt to reproduce. Can anyone else?

@SiegeLord
Copy link
Contributor Author

The error from 2016 still happens on Linux.

@torhovland
Copy link
Contributor

@rustbot claim

@jyn514
Copy link
Member

jyn514 commented Apr 4, 2021

The error from 2016 still happens on Linux.

I had trouble reproducing with --crate-type lib and --crate-type rlib, but changing rlib to cdylib consistently gives

error: linking with `cc` failed: exit status: 1
  = note: cc: error: lib.lib.3a1fbbbh-cgu.0.rcgu.o: No such file or directory

@jyn514
Copy link
Member

jyn514 commented Apr 4, 2021

Add some kind of hash to the names of the intermediates to stop them from colliding. Can't just be the pkgid hash, as it'd still fail the above test.

I think hashing the command line arguments would work.

@torhovland
Copy link
Contributor

I had trouble reproducing with --crate-type lib and --crate-type rlib, but changing rlib to cdylib consistently gives

error: linking with `cc` failed: exit status: 1
  = note: cc: error: lib.lib.3a1fbbbh-cgu.0.rcgu.o: No such file or directory

OK, I just checked that my PR does fix that (using --temps-dir).

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 16, 2021
Added the --temps-dir option

Fixes rust-lang#10971.

The new `--temps-dir` option puts intermediate files in a user-specified directory. This provides a fix for the issue where parallel invocations of rustc would overwrite each other's intermediate files.

No files are kept in the intermediate directory unless `-C save-temps=yes`.

If additional files are specifically requested using `--emit asm,llvm-bc,llvm-ir,obj,metadata,link,dep-info,mir`, these will be put in the output directory rather than the intermediate directory.

This is a backward-compatible change, i.e. if `--temps-dir` is not specified, the behavior is the same as before.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 9, 2021
Added the --temps-dir option

Fixes rust-lang#10971.

The new `--temps-dir` option puts intermediate files in a user-specified directory. This provides a fix for the issue where parallel invocations of rustc would overwrite each other's intermediate files.

No files are kept in the intermediate directory unless `-C save-temps=yes`.

If additional files are specifically requested using `--emit asm,llvm-bc,llvm-ir,obj,metadata,link,dep-info,mir`, these will be put in the output directory rather than the intermediate directory.

This is a backward-compatible change, i.e. if `--temps-dir` is not specified, the behavior is the same as before.
@bors bors closed this as completed in 9dbbbb1 Nov 11, 2021
flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 31, 2023
…ix, r=dswij

Check for fully qualified paths in `unnecessary_cast`

Noticed this doesn't pick up `::std::primitive::u32` or the sort, now it does
changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants