Index: ELF/OutputSections.h =================================================================== --- ELF/OutputSections.h +++ ELF/OutputSections.h @@ -115,7 +115,8 @@ private: // Used for implementation of --compress-debug-sections option. std::vector ZDebugHeader; - llvm::SmallVector CompressedData; + std::unique_ptr CompressedData; + size_t CompressedSize; uint32_t getFiller(); }; Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -197,11 +197,12 @@ // Write section contents to a temporary buffer and compress it. std::vector Buf(Size); writeTo(Buf.data()); - if (Error E = zlib::compress(toStringRef(Buf), CompressedData)) + if (Error E = + zlib::compress(toStringRef(Buf), CompressedData, CompressedSize)) fatal("compress failed: " + llvm::toString(std::move(E))); // Update section headers. - Size = sizeof(Elf_Chdr) + CompressedData.size(); + Size = sizeof(Elf_Chdr) + CompressedSize; Flags |= SHF_COMPRESSED; } @@ -227,10 +228,9 @@ // If -compress-debug-section is specified and if this is a debug seciton, // we've already compressed section contents. If that's the case, // just write it down. - if (!CompressedData.empty()) { + if (CompressedData) { memcpy(Buf, ZDebugHeader.data(), ZDebugHeader.size()); - memcpy(Buf + ZDebugHeader.size(), CompressedData.data(), - CompressedData.size()); + memcpy(Buf + ZDebugHeader.size(), CompressedData.get(), CompressedSize); return; }