diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-04-18 21:52:26 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-04-18 21:52:26 +0000 |
commit | 2e3463ec43ab3ffc1c4e07f870f5c9a14279aa17 (patch) | |
tree | 8ca45e8c1fb5bf5d9b2510ca2d07f37ce4aa9495 /lib | |
parent | e153fb33e49bd6d44189d3659287338c410bc0ce (diff) | |
download | llvm-2e3463ec43ab3ffc1c4e07f870f5c9a14279aa17.tar.gz llvm-2e3463ec43ab3ffc1c4e07f870f5c9a14279aa17.tar.bz2 llvm-2e3463ec43ab3ffc1c4e07f870f5c9a14279aa17.tar.xz |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/ELFObjectWriter.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
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<char> &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<char *>(&Size), reinterpret_cast<char *>(&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; } |