-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Specify dlltool prefix when generating import libs #107752
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. Please see the contribution instructions for more information. |
cc @mati865 |
@bors r+ |
…efix, r=petrochenkov Specify dlltool prefix when generating import libs Ref: rust-lang#106610 (comment) tl;dr: This PR adds an explicit dlltool temporary filename prefix. The prefix resolves a race condition by ensuring dlltool temporary files are siloed in an appropriate/unique Rust temporary directory. --- GNU dlltool, as part of its import library generation logic, uses a bunch of temporary files on disk. In the interest of deterministic build runs, dlltool supports deterministic temporary filenames. The temporary filename prefix is automatically generated internally or can be explicitly specified via a `--temp-prefix` argument. GNU dlltool **2.38** (that ships with `x86_64-12.2.0-release-posix-seh-rt_v10-rev0` [installed during CI](https://github.com/rust-lang/rust/blob/master/src/ci/scripts/install-mingw.sh)) generates a prefix based on the target library name ([source](https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=binutils/dlltool.c;h=d95bf3f5470b999fa3b30bc887791859f48d81d1;hb=20756b0fbe065a84710aa38f2457563b57546440#l3992)). The tool writes to files such as `target_dll_h.s` and `target_dll_s00203.o` in the current working directory. This presents a problem when multiple instances of rustc_codegen_llvm are running to generate an import library (as part of the raw_dylib feature) for the same target library (e.g. kernel32) ([source](https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/back/archive.rs#L185-L196)). That is, dlltool instances race and may overwrite or delete files belonging to each other. GNU dlltool **2.39**+ (not used in Rust CI) generates a prefix based on the output library path ([source](https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=binutils/dlltool.c;h=e2af20847009945b4c61a6fef08268fbb4429715;hb=b51c2fec1da205ea3e7354cbb3e253018d64873c#l3992)). The tool, when invoked as part of rustc_codegen_llvm, writes to files at paths such as `C_Users_Foo_AppData_Local_Temp_rustcOFqhXZ_target_lib_h.s`. (The output library path is normalized and non-alphanumeric characters are replaced with underscores.)
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#107446 (Migrate some of `rustc_parse` to derive diagnostics) - rust-lang#107752 (Specify dlltool prefix when generating import libs) - rust-lang#107808 (bootstrap.py: fix build-failure message) - rust-lang#107834 (create symlink for legacy rustfmt path) - rust-lang#107835 (use idiomatic formatting) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The |
It looks like llvm-dlltool is not susceptible to this race condition, although it does use random temp files. A fix to recognize and ignore this flag has been upstreamed as https://reviews.llvm.org/D152361. |
FYI if you build tier 3 |
That's good to know. I think it's better for us to stick to pc-windows-gnu for now as it's better supported. We have some workarounds, including cherrypicking the llvm patch into our toolchain build. |
I think I'm going to play around with gnullvm a bit. It's an interesting option. Thanks for the suggestion. |
Ref: #106610 (comment)
tl;dr: This PR adds an explicit dlltool temporary filename prefix. The prefix resolves a race condition by ensuring dlltool temporary files are siloed in an appropriate/unique Rust temporary directory.
GNU dlltool, as part of its import library generation logic, uses a bunch of temporary files on disk. In the interest of deterministic build runs, dlltool supports deterministic temporary filenames. The temporary filename prefix is automatically generated internally or can be explicitly specified via a
--temp-prefix
argument.GNU dlltool 2.38 (that ships with
x86_64-12.2.0-release-posix-seh-rt_v10-rev0
installed during CI) generates a prefix based on the target library name (source). The tool writes to files such astarget_dll_h.s
andtarget_dll_s00203.o
in the current working directory.This presents a problem when multiple instances of rustc_codegen_llvm are running to generate an import library (as part of the raw_dylib feature) for the same target library (e.g. kernel32) (source). That is, dlltool instances race and may overwrite or delete files belonging to each other.
GNU dlltool 2.39+ (not used in Rust CI) generates a prefix based on the output library path (source). The tool, when invoked as part of rustc_codegen_llvm, writes to files at paths such as
C_Users_Foo_AppData_Local_Temp_rustcOFqhXZ_target_lib_h.s
. (The output library path is normalized and non-alphanumeric characters are replaced with underscores.)