[PATCH] D142985: [LinkerWrapper] Fix memory issues due to unguarded accesses to global state
Joseph Huber via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 1 06:12:18 PST 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9c4591d7f3ac: [LinkerWrapper] Fix memory issues due to unguarded accesses to global state (authored by jhuber6).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142985/new/
https://reviews.llvm.org/D142985
Files:
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===================================================================
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -77,6 +77,9 @@
/// Binary path for the CUDA installation.
static std::string CudaBinaryPath;
+/// Mutex lock to protect writes to shared TempFiles in parallel.
+static std::mutex TempFilesMutex;
+
/// Temporary files created by the linker wrapper.
static std::list<SmallString<128>> TempFiles;
@@ -200,6 +203,7 @@
/// Get a temporary filename suitable for output.
Expected<StringRef> createOutputFile(const Twine &Prefix, StringRef Extension) {
+ std::scoped_lock<decltype(TempFilesMutex)> Lock(TempFilesMutex);
SmallString<128> OutputFile;
if (SaveTemps) {
(Prefix + "." + Extension).toNullTerminatedStringRef(OutputFile);
@@ -1047,6 +1051,7 @@
return createFileError(*OutputOrErr, EC);
}
+ std::scoped_lock<decltype(ImageMtx)> Guard(ImageMtx);
OffloadingImage TheImage{};
TheImage.TheImageKind =
Args.hasArg(OPT_embed_bitcode) ? IMG_Bitcode : IMG_Object;
@@ -1058,7 +1063,6 @@
Args.MakeArgString(LinkerArgs.getLastArgValue(OPT_arch_EQ))}};
TheImage.Image = std::move(*FileOrErr);
- std::lock_guard<decltype(ImageMtx)> Guard(ImageMtx);
Images[Kind].emplace_back(std::move(TheImage));
}
return Error::success();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142985.493928.patch
Type: text/x-patch
Size: 1483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230201/f325a079/attachment-0001.bin>
More information about the cfe-commits
mailing list