Skip to content

Commit

Permalink
[ELF] toString(const InputFile *): synchronize toStringCache
Browse files Browse the repository at this point in the history
The function may be called currently for diagnostics.
  • Loading branch information
MaskRay committed Aug 6, 2022
1 parent 6a275cd commit e45a569
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lld/ELF/InputFiles.cpp
Expand Up @@ -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);
}
Expand Down

0 comments on commit e45a569

Please sign in to comment.