swift-foundation
swift-foundation copied to clipboard
FoundationEssentials: Use of mktemp causes linker warning with -static-stdlib
In FoundationEssentials' Data class, there's a commented use of mktemp.
https://github.com/swiftlang/swift-foundation/blob/5af94abeed723989842534e0a451ae07e4bd22ba/Sources/FoundationEssentials/Data/Data%2BWriting.swift#L168-L182
As the comment describes, this use is "fine" :tm:. It also describes a reason that the preferred mkstemp method cannot be used.
It seems to reference an Apple-internal bug ID, so here's a public one :)
The behavior I'm seeing in my own project is that use of -static-stdlib forces this 'bad' API usage to show up in my own build logs when linking a shared library on Linux:
/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/lib/swift_static/linux/libFoundationEssentials.a(Data+Writing.swift.o):
_ThreadLocal.swift.o:function $s20FoundationEssentials19createTemporaryFile33_FC9EC52B075D2ACCFF86F1C9F84293BELL2at6inPath6prefix7options7variants5Int32V_SStSS_AA0Q5OrURLOSSAA4DataV14WritingOptionsVSSSgtKFAJ_SStSgSpys4Int8VGSgKXEfU_:
(.text+0xac9): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
$ swiftc -version
Swift version 6.2-dev (LLVM b5d039be1fbae13, Swift 4fb4945ab972c85)
Target: x86_64-unknown-linux-gnu
Build config: +assertions
As the error suggests, this is swiftly main-snapshot-06-03.