[lld] e45a569 - [ELF] toString(const InputFile *): synchronize toStringCache
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 6 01:00:13 PDT 2022
Author: Fangrui Song
Date: 2022-08-06T01:00:06-07:00
New Revision: e45a5696bb2ae5d12ada5000135e45366f6582b1
URL: https://github.com/llvm/llvm-project/commit/e45a5696bb2ae5d12ada5000135e45366f6582b1
DIFF: https://github.com/llvm/llvm-project/commit/e45a5696bb2ae5d12ada5000135e45366f6582b1.diff
LOG: [ELF] toString(const InputFile *): synchronize toStringCache
The function may be called currently for diagnostics.
Added:
Modified:
lld/ELF/InputFiles.cpp
Removed:
################################################################################
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 36500652d07fa..c0961b49ff389 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -47,14 +47,18 @@ std::unique_ptr<TarWriter> elf::tar;
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
std::string lld::toString(const InputFile *f) {
+ static std::mutex mu;
if (!f)
return "<internal>";
- if (f->toStringCache.empty()) {
- if (f->archiveName.empty())
- f->toStringCache = f->getName();
- else
- (f->archiveName + "(" + f->getName() + ")").toVector(f->toStringCache);
+ {
+ std::lock_guard<std::mutex> lock(mu);
+ if (f->toStringCache.empty()) {
+ if (f->archiveName.empty())
+ f->toStringCache = f->getName();
+ else
+ (f->archiveName + "(" + f->getName() + ")").toVector(f->toStringCache);
+ }
}
return std::string(f->toStringCache);
}
More information about the llvm-commits
mailing list