]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #107752 - riverar:rafael/gnu_dlltool_temp_prefix, r=petrochenkov
authorMatthias Krüger <matthias.krueger@famsik.de>
Thu, 9 Feb 2023 10:21:58 +0000 (11:21 +0100)
committerGitHub <noreply@github.com>
Thu, 9 Feb 2023 10:21:58 +0000 (11:21 +0100)
commita62176988161bad4f4dc21f99e9c1f2a5060b0a7
tree00020d192dac02fe18c3160f29755991a6e8b5b3
parent3b9543c89d1909bae143bfe9a87d3248d1526cf2
parentc825e08571136deb5643ccd42bddf76b799ea93b
Rollup merge of #107752 - riverar:rafael/gnu_dlltool_temp_prefix, r=petrochenkov

Specify dlltool prefix when generating import libs

Ref: https://github.com/rust-lang/rust/pull/106610#issuecomment-1418221274

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.)