From c19728fa10d953dee24b5378a79d52f1653ffb9a Mon Sep 17 00:00:00 2001 From: George Rimar Date: Tue, 24 May 2016 09:44:44 +0000 Subject: [PATCH] Revert r270540 "[llvm-dwarfdump] - Teach dwarfdump to decompress debug sections in zlib style." it broked bot: http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/5036 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270541 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/COFF.h | 1 - include/llvm/Object/ELFObjectFile.h | 6 -- include/llvm/Object/MachO.h | 1 - include/llvm/Object/ObjectFile.h | 6 -- lib/DebugInfo/DWARF/DWARFContext.cpp | 68 ++++-------------- lib/Object/COFFObjectFile.cpp | 4 -- lib/Object/MachOObjectFile.cpp | 4 -- test/DebugInfo/Inputs/dwarfdump-test-zlib.cc | 8 +-- .../Inputs/dwarfdump-test-zlibgnu.elf-x86-64 | Bin 10320 -> 0 bytes test/DebugInfo/dwarfdump-zlib.test | 6 -- 10 files changed, 18 insertions(+), 86 deletions(-) delete mode 100644 test/DebugInfo/Inputs/dwarfdump-test-zlibgnu.elf-x86-64 diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index aa12418f2d3..7553f4bdaf7 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -694,7 +694,6 @@ protected: std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override; uint64_t getSectionAlignment(DataRefImpl Sec) const override; - bool isSectionCompressed(DataRefImpl Sec) const override; bool isSectionText(DataRefImpl Sec) const override; bool isSectionData(DataRefImpl Sec) const override; bool isSectionBSS(DataRefImpl Sec) const override; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 52cde1a0f0f..c5f777186aa 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -222,7 +222,6 @@ protected: std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override; uint64_t getSectionAlignment(DataRefImpl Sec) const override; - bool isSectionCompressed(DataRefImpl Sec) const override; bool isSectionText(DataRefImpl Sec) const override; bool isSectionData(DataRefImpl Sec) const override; bool isSectionBSS(DataRefImpl Sec) const override; @@ -584,11 +583,6 @@ uint64_t ELFObjectFile::getSectionAlignment(DataRefImpl Sec) const { return getSection(Sec)->sh_addralign; } -template -bool ELFObjectFile::isSectionCompressed(DataRefImpl Sec) const { - return getSection(Sec)->sh_flags & ELF::SHF_COMPRESSED; -} - template bool ELFObjectFile::isSectionText(DataRefImpl Sec) const { return getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR; diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 6a079a964bf..611acf3124d 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -222,7 +222,6 @@ public: std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override; uint64_t getSectionAlignment(DataRefImpl Sec) const override; - bool isSectionCompressed(DataRefImpl Sec) const override; bool isSectionText(DataRefImpl Sec) const override; bool isSectionData(DataRefImpl Sec) const override; bool isSectionBSS(DataRefImpl Sec) const override; diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 0f0f10b8c19..0a902a4590a 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -89,7 +89,6 @@ public: /// @brief Get the alignment of this section as the actual value (not log 2). uint64_t getAlignment() const; - bool isCompressed() const; bool isText() const; bool isData() const; bool isBSS() const; @@ -215,7 +214,6 @@ protected: virtual std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const = 0; virtual uint64_t getSectionAlignment(DataRefImpl Sec) const = 0; - virtual bool isSectionCompressed(DataRefImpl Sec) const = 0; virtual bool isSectionText(DataRefImpl Sec) const = 0; virtual bool isSectionData(DataRefImpl Sec) const = 0; virtual bool isSectionBSS(DataRefImpl Sec) const = 0; @@ -382,10 +380,6 @@ inline uint64_t SectionRef::getAlignment() const { return OwningObject->getSectionAlignment(SectionPimpl); } -inline bool SectionRef::isCompressed() const { - return OwningObject->isSectionCompressed(SectionPimpl); -} - inline bool SectionRef::isText() const { return OwningObject->isSectionText(SectionPimpl); } diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index 27b8c564d91..d3b5e736c48 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -15,7 +15,6 @@ #include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h" #include "llvm/Support/Compression.h" #include "llvm/Support/Dwarf.h" -#include "llvm/Support/ELF.h" #include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" @@ -591,8 +590,8 @@ DWARFContext::getInliningInfoForAddress(uint64_t Address, return InliningInfo; } -static bool consumeCompressedGnuHeader(StringRef &data, - uint64_t &OriginalSize) { +static bool consumeCompressedDebugSectionHeader(StringRef &data, + uint64_t &OriginalSize) { // Consume "ZLIB" prefix. if (!data.startswith("ZLIB")) return false; @@ -607,50 +606,6 @@ static bool consumeCompressedGnuHeader(StringRef &data, return true; } -static bool consumeCompressedZLibHeader(StringRef &Data, uint64_t &OriginalSize, - bool IsLE, bool Is64Bit) { - using namespace ELF; - uint64_t HdrSize = Is64Bit ? sizeof(Elf64_Chdr) : sizeof(Elf32_Chdr); - if (Data.size() < HdrSize) - return false; - - DataExtractor Extractor(Data, IsLE, 0); - uint32_t Offset = 0; - if (Extractor.getUnsigned(&Offset, Is64Bit ? sizeof(Elf64_Word) - : sizeof(Elf32_Word)) != - ELFCOMPRESS_ZLIB) - return false; - - // Skip Elf64_Chdr::ch_reserved field. - if (Is64Bit) - Offset += sizeof(Elf64_Word); - - OriginalSize = Extractor.getUnsigned(&Offset, Is64Bit ? sizeof(Elf64_Xword) - : sizeof(Elf32_Word)); - Data = Data.substr(HdrSize); - return true; -} - -static bool tryDecompress(StringRef &Name, StringRef &Data, - SmallString<32> &Out, bool ZLibStyle, bool IsLE, - bool Is64Bit) { - if (!zlib::isAvailable()) - return false; - - uint64_t OriginalSize; - bool Result = - ZLibStyle ? consumeCompressedZLibHeader(Data, OriginalSize, IsLE, Is64Bit) - : consumeCompressedGnuHeader(Data, OriginalSize); - - if (!Result || zlib::uncompress(Data, Out, OriginalSize) != zlib::StatusOK) - return false; - - // gnu-style names are started from "z", consume that. - if (!ZLibStyle) - Name = Name.substr(1); - return true; -} - DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L) : IsLittleEndian(Obj.isLittleEndian()), @@ -676,13 +631,20 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, name = name.substr(name.find_first_not_of("._")); // Skip . and _ prefixes. - bool ZLibStyleCompressed = Section.isCompressed(); - if (ZLibStyleCompressed || name.startswith("zdebug_")) { - SmallString<32> Out; - if (!tryDecompress(name, data, Out, ZLibStyleCompressed, IsLittleEndian, - AddressSize == 8)) + // Check if debug info section is compressed with zlib. + if (name.startswith("zdebug_")) { + uint64_t OriginalSize; + if (!zlib::isAvailable() || + !consumeCompressedDebugSectionHeader(data, OriginalSize)) continue; - UncompressedSections.emplace_back(std::move(Out)); + UncompressedSections.resize(UncompressedSections.size() + 1); + if (zlib::uncompress(data, UncompressedSections.back(), OriginalSize) != + zlib::StatusOK) { + UncompressedSections.pop_back(); + continue; + } + // Make data point to uncompressed section contents and save its contents. + name = name.substr(1); data = UncompressedSections.back(); } diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 489c69cc4bc..4b6ab23f5ff 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -292,10 +292,6 @@ uint64_t COFFObjectFile::getSectionAlignment(DataRefImpl Ref) const { return Sec->getAlignment(); } -bool COFFObjectFile::isSectionCompressed(DataRefImpl Sec) const { - return false; -} - bool COFFObjectFile::isSectionText(DataRefImpl Ref) const { const coff_section *Sec = toSec(Ref); return Sec->Characteristics & COFF::IMAGE_SCN_CNT_CODE; diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index d7ec3e57a58..760249f56a8 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -653,10 +653,6 @@ uint64_t MachOObjectFile::getSectionAlignment(DataRefImpl Sec) const { return uint64_t(1) << Align; } -bool MachOObjectFile::isSectionCompressed(DataRefImpl Sec) const { - return false; -} - bool MachOObjectFile::isSectionText(DataRefImpl Sec) const { uint32_t Flags = getSectionFlags(this, Sec); return Flags & MachO::S_ATTR_PURE_INSTRUCTIONS; diff --git a/test/DebugInfo/Inputs/dwarfdump-test-zlib.cc b/test/DebugInfo/Inputs/dwarfdump-test-zlib.cc index fc60ea3449a..260c3c435c1 100644 --- a/test/DebugInfo/Inputs/dwarfdump-test-zlib.cc +++ b/test/DebugInfo/Inputs/dwarfdump-test-zlib.cc @@ -16,11 +16,9 @@ int main() { return f(2, 3); } -// Built with Clang 3.9 and GNU gold (GNU Binutils for Ubuntu 2.26) 1.11: +// Built with Clang 3.2 and ld.gold linker: // $ mkdir -p /tmp/dbginfo // $ cp dwarfdump-test-zlib.cc /tmp/dbginfo // $ cd /tmp/dbginfo -// $ clang++ -g dwarfdump-test-zlib.cc -Wl,--compress-debug-sections=zlib -o dwarfdump-test-zlib.elf-x86-64 -// $ clang++ -g dwarfdump-test-zlib.cc -Wl,--compress-debug-sections=zlib-gnu -o dwarfdump-test-zlibgnu.elf-x86-64 -// llvm-readobj -sections can be used to see that outputs really contain the compressed sections, also output in both -// cases is slightly smaller, that is because of compression. \ No newline at end of file +// $ clang++ -g dwarfdump-test-zlib.cc -Wl,--compress-debug-sections=zlib \ +// -o diff --git a/test/DebugInfo/Inputs/dwarfdump-test-zlibgnu.elf-x86-64 b/test/DebugInfo/Inputs/dwarfdump-test-zlibgnu.elf-x86-64 deleted file mode 100644 index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Zw-`BNMP5JTDr%ul6JO2HXuM9T#&+Gf?_jXTllq~5j?%jPbc>n$L4;CM+Dtb=X zZaR0r^Wl+f@9wi3j?FXI7yQrQK+1Q&()CL8xsN+;_rBBet0wOums@y6VA1{N9lAjF zb?$Ba&a0D;6m6>4Qx z&w4-j(`Y!TY4}Mffl)vg^tQPWzH#OjX;5t+))3VHS`(PTFs^oA6T}b*qkE9x_Gg9th*{x{&IY4|-ARz>Xl zQJF~wF8(_+)frSF+|X9v@EdeGT-pMQ|6WVK<4SsC=+pNV65F7o$J2Q<%pKDA39>ih zD?#xI)BX;JuYyloc5bG&fQqISOYSw zjS!xRGH}p%!K6&%Vs~Ty?gI_hHV9AW<4B61?1+9H^jIq)UgqP=94~P^`q9VF z#SG68m{Y<#Io`?fdEAi3H_m?x$Cq3L$=q>|(h~tMip5i6Ek$>EPALjUBj?baQatAan`FqlUr+ULho^Yy* zk-c&KKg02{-|*99&6Fq9Xiq%R=Qy6ijQ@W^b5pC4*qv}BI0793F2YltVCKnG%SvaiGzjr-R^31Odv5ViK)G_>~4Z;fdmJz|_~9zRwHlReB-x zjkecMfVc6DXW(=2^CrMw;`k>&2ft_nd=D?J;r^y?#`vo_-k86e_>1qmdNA|}PqdEX z4QA{B$CDlDjl63D{6UVNOF&MI`1>copW%4x=iswJPis$aI+>Rmy9@&wST!HCcj@t6 jeEpW;mlJ4n;93Y5t!H{KP6Ao7@elJKK;|2q8^`|#5{}tw diff --git a/test/DebugInfo/dwarfdump-zlib.test b/test/DebugInfo/dwarfdump-zlib.test index d3ef806f3f8..cbd85ca093c 100644 --- a/test/DebugInfo/dwarfdump-zlib.test +++ b/test/DebugInfo/dwarfdump-zlib.test @@ -1,12 +1,6 @@ REQUIRES: zlib RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test-zlib.elf-x86-64 | FileCheck %s -RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test-zlibgnu.elf-x86-64 | FileCheck %s CHECK: .debug_abbrev contents - -// Dump content of a little section to check that both zlib and zlib gnu styles do -// the decompression correctly and result is the same. This and above also checks -// that sections names are properly shown in zlib-gnu style (without additional 'z' prefix). CHECK: .debug_info contents -CHECK: 0x00000000: Compile Unit: length = 0x00000144 version = 0x0004 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x00000148)