From 2e3463ec43ab3ffc1c4e07f870f5c9a14279aa17 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 18 Apr 2014 21:52:26 +0000 Subject: Compress debug sections only when beneficial. Both ZLIB and the debug info compressed section header ("ZLIB" + the size of the uncompressed data) take some constant overhead so in some cases the compressed data is actually larger than the uncompressed data. In these cases, just don't compress or rename the section at all. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206659 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index c064e24128..de05501756 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -1209,10 +1209,12 @@ getUncompressedData(MCAsmLayout &Layout, // Include the debug info compression header: // "ZLIB" followed by 8 bytes representing the uncompressed size of the section, // useful for consumers to preallocate a buffer to decompress into. -static void +static bool prependCompressionHeader(uint64_t Size, SmallVectorImpl &CompressedContents) { static const StringRef Magic = "ZLIB"; + if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size()) + return false; if (sys::IsLittleEndianHost) Size = sys::SwapByteOrder(Size); CompressedContents.insert(CompressedContents.begin(), @@ -1221,6 +1223,7 @@ prependCompressionHeader(uint64_t Size, std::copy(reinterpret_cast(&Size), reinterpret_cast(&Size + 1), CompressedContents.begin() + Magic.size()); + return true; } // Return a single fragment containing the compressed contents of the whole @@ -1243,7 +1246,8 @@ getCompressedFragment(MCAsmLayout &Layout, if (Success != zlib::StatusOK) return nullptr; - prependCompressionHeader(UncompressedData.size(), CompressedContents); + if (!prependCompressionHeader(UncompressedData.size(), CompressedContents)) + return nullptr; return CompressedFragment; } -- cgit v1.2.3