ELF: Use bump pointer allocator for uncompressed section buffers. NFCI.

This shaves another word off SectionBase and makes it possible to clone a
section using the implicit copy constructor.

This basically reverts r311056, which removed the mutex in order to
make the code easier to understand. On balance I think it's probably more
straightforward to have a mutex here than to have an unusual copy constructor
in SectionBase.

Differential Revision: https://reviews.llvm.org/D59269

llvm-svn: 355966
This commit is contained in:
Peter Collingbourne
2019-03-12 20:32:30 +00:00
parent 2a3de8f437
commit e2b8c40a77
2 changed files with 16 additions and 10 deletions

View File

@@ -144,13 +144,18 @@ size_t InputSectionBase::getSize() const {
void InputSectionBase::uncompress() const {
size_t Size = UncompressedSize;
UncompressedBuf.reset(new char[Size]);
char *UncompressedBuf;
{
static std::mutex Mu;
std::lock_guard<std::mutex> Lock(Mu);
UncompressedBuf = BAlloc.Allocate<char>(Size);
}
if (Error E =
zlib::uncompress(toStringRef(RawData), UncompressedBuf.get(), 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.get(), Size);
RawData = makeArrayRef((uint8_t *)UncompressedBuf, Size);
UncompressedSize = -1;
}
uint64_t InputSectionBase::getOffsetInFile() const {
@@ -1062,7 +1067,7 @@ template <class ELFT> void InputSection::writeTo(uint8_t *Buf) {
// If this is a compressed section, uncompress section contents directly
// to the buffer.
if (UncompressedSize >= 0 && !UncompressedBuf) {
if (UncompressedSize >= 0) {
size_t Size = UncompressedSize;
if (Error E = zlib::uncompress(toStringRef(RawData),
(char *)(Buf + OutSecOff), Size))