On Mon, 4 Mar 2024, Mateusz Mikuła wrote:

rand is not random enough and may lead to clashing temporary directories
with multiple parallel link processes as it was observed on Rust's CI.

It can be reproduced with these commands (run them all in without long pauses):

for n in {1..15000}; do rm -f lib/libLLVMAVRAsmParser.a && \
ar qc lib/libLLVMAVRAsmParser.a 
&& \
ranlib.exe lib/libLLVMAVRAsmParser.a; done &

for n in {1..15000}; do rm -f lib/libLLVMSparcCodeGen.a && \
ar qc lib/libLLVMSparcCodeGen.a lib/Target/Sparc/CMakeFiles/LLVMSparcCodeGen.dir/*.obj 
&& \
ranlib.exe lib/libLLVMSparcCodeGen.a; done

echo "done"

Before the patch it will fail with an error: ranlib.exe: could not create 
temporary file whilst writing archive: no more archived files.

Thanks, I've run into this issue occasionally when building LLVM on msys2 as well, but I've failed to reproduce it when I've tried to look closer at it (as I've missed the issue that one needs to build two archives at the same time in order to trigger it).

If the issue is that the randomness clashes, shouldn't that be something that, as part of the contract of mkstemp, the function should retry until it finds a non-conflicting combination? But, thinking further, is the issue that two processes end up trying the same sequence of pseudo random files, which all then end up clashing, and mkstemp returns an error as it was unable to find a unique file name? I guess that's plausible. In that case, I guess this patch is fine (with Liu Hao's suggestion), as a way to reduce the risk of running into this.

// Martin

Mingw-w64-public mailing list

Reply via email to