diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -157,8 +157,7 @@ } ArrayRef data() const { - if (uncompressedSize >= 0) - uncompress(); + uncompress(); return rawData; } diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -118,17 +118,24 @@ void InputSectionBase::uncompress() const { size_t size = uncompressedSize; char *uncompressedBuf; + static std::mutex mu; { - static std::mutex mu; std::lock_guard lock(mu); + if (uncompressedSize <= 0) + return; uncompressedBuf = bAlloc().Allocate(size); } if (Error e = zlib::uncompress(toStringRef(rawData), uncompressedBuf, size)) fatal(toString(this) + ": uncompress failed: " + llvm::toString(std::move(e))); - rawData = makeArrayRef((uint8_t *)uncompressedBuf, size); - uncompressedSize = -1; + + { + std::lock_guard lock(mu); + if (uncompressedSize <= 0) + rawData = makeArrayRef((uint8_t *)uncompressedBuf, size); + uncompressedSize = -1; + } } template RelsOrRelas InputSectionBase::relsOrRelas() const {