Skip to content

Commit 314a005

Browse files
committed
Remove a lock and use a std::unique_ptr instead.
We had a lock to guard BAlloc from being used concurrently, but that is not very easy to understand. This patch replaces it with a std::unique_ptr. llvm-svn: 311056
1 parent 42a5353 commit 314a005

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lld/ELF/InputSection.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,12 @@ void InputSectionBase::uncompress() {
200200
Config->IsLE, Config->Is64));
201201

202202
size_t Size = Dec.getDecompressedSize();
203-
char *OutputBuf;
204-
{
205-
static std::mutex Mu;
206-
std::lock_guard<std::mutex> Lock(Mu);
207-
OutputBuf = BAlloc.Allocate<char>(Size);
208-
}
209-
210-
if (Error E = Dec.decompress({OutputBuf, Size}))
203+
UncompressBuf.reset(new std::vector<uint8_t>(Size));
204+
if (Error E = Dec.decompress({(char *)UncompressBuf->data(), Size}))
211205
fatal(toString(this) +
212206
": decompress failed: " + llvm::toString(std::move(E)));
213-
this->Data = ArrayRef<uint8_t>((uint8_t *)OutputBuf, Size);
207+
208+
this->Data = *UncompressBuf;
214209
this->Flags &= ~(uint64_t)SHF_COMPRESSED;
215210
}
216211

lld/ELF/InputSection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ class InputSectionBase : public SectionBase {
183183
assert(S % sizeof(T) == 0);
184184
return llvm::makeArrayRef<T>((const T *)Data.data(), S / sizeof(T));
185185
}
186+
187+
private:
188+
// A pointer that owns uncompressed data if a section is compressed by zlib.
189+
// Since the feature is not used often, this is usually a nullptr.
190+
std::unique_ptr<std::vector<uint8_t>> UncompressBuf;
186191
};
187192

188193
// SectionPiece represents a piece of splittable section contents.

0 commit comments

Comments
 (0)