diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 36500652d07f..c0961b49ff38 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -47,14 +47,18 @@ std::unique_ptr elf::tar; // Returns "", "foo.a(bar.o)" or "baz.o". std::string lld::toString(const InputFile *f) { + static std::mutex mu; if (!f) return ""; - if (f->toStringCache.empty()) { - if (f->archiveName.empty()) - f->toStringCache = f->getName(); - else - (f->archiveName + "(" + f->getName() + ")").toVector(f->toStringCache); + { + std::lock_guard 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); }