diff options
author | George Rimar <grimar@accesssoftek.com> | 2017-05-05 10:52:39 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2017-05-05 10:52:39 +0000 |
commit | 2122ff64c6ef776d37592a7fc3f4029cdef46fe2 (patch) | |
tree | c63542fbf9e5ca7f96a212b629a1a864f8bee494 | |
parent | 3559f20f17f7fa85a9b6c1d7dc8be3b3b6103d81 (diff) | |
download | bcm5719-llvm-2122ff64c6ef776d37592a7fc3f4029cdef46fe2.tar.gz bcm5719-llvm-2122ff64c6ef776d37592a7fc3f4029cdef46fe2.zip |
[llvm-dwarfdump] - Print an error message if section decompression failed.
llvm-dwarfdump currently prints no message if decompression fails
for some reason. I noticed that during work on one of LLD patches
where LLD produced an broken output. It was a bit confusing to see
no output for section dumped and no any error message at all.
Patch adds error message for such cases.
Differential revision: https://reviews.llvm.org/D32865
llvm-svn: 302221
-rw-r--r-- | llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h | 3 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 35 | ||||
-rw-r--r-- | llvm/test/DebugInfo/Inputs/dwarfdump-decompression-error.elf-x86-64 | bin | 0 -> 7096 bytes | |||
-rw-r--r-- | llvm/test/DebugInfo/dwarfdump-decompression-error.test | 15 |
4 files changed, 43 insertions, 10 deletions
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h index b9f3425d5de..d42c477e7de 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -310,6 +310,9 @@ class DWARFContextInMemory : public DWARFContext { StringRef *MapSectionToMember(StringRef Name); + Error maybeDecompress(const object::SectionRef &Sec, StringRef Name, + StringRef &Data); + public: DWARFContextInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp index 179d6afa579..246899ac12b 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -957,6 +957,26 @@ static bool isRelocScattered(const object::ObjectFile &Obj, return MachObj->isRelocationScattered(RelocInfo); } +Error DWARFContextInMemory::maybeDecompress(const SectionRef &Sec, + StringRef Name, StringRef &Data) { + if (!Decompressor::isCompressed(Sec)) + return Error::success(); + + Expected<Decompressor> Decompressor = + Decompressor::create(Name, Data, IsLittleEndian, AddressSize == 8); + if (!Decompressor) + return Decompressor.takeError(); + + SmallString<32> Out; + if (auto Err = Decompressor->decompress(Out)) + return Err; + + UncompressedSections.emplace_back(std::move(Out)); + Data = UncompressedSections.back(); + + return Error::success(); +} + DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L) : IsLittleEndian(Obj.isLittleEndian()), @@ -980,16 +1000,11 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, if (!L || !L->getLoadedSectionContents(*RelocatedSection,data)) Section.getContents(data); - if (Decompressor::isCompressed(Section)) { - Expected<Decompressor> Decompressor = - Decompressor::create(name, data, IsLittleEndian, AddressSize == 8); - if (!Decompressor) - continue; - SmallString<32> Out; - if (auto Err = Decompressor->decompress(Out)) - continue; - UncompressedSections.emplace_back(std::move(Out)); - data = UncompressedSections.back(); + if (auto Err = maybeDecompress(Section, name, data)) { + errs() << "error: failed to decompress '" + name + "', " + + toString(std::move(Err)) + << '\n'; + continue; } // Compressed sections names in GNU style starts from ".z", diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-decompression-error.elf-x86-64 b/llvm/test/DebugInfo/Inputs/dwarfdump-decompression-error.elf-x86-64 Binary files differnew file mode 100644 index 00000000000..ba352f51123 --- /dev/null +++ b/llvm/test/DebugInfo/Inputs/dwarfdump-decompression-error.elf-x86-64 diff --git a/llvm/test/DebugInfo/dwarfdump-decompression-error.test b/llvm/test/DebugInfo/dwarfdump-decompression-error.test new file mode 100644 index 00000000000..184833164dc --- /dev/null +++ b/llvm/test/DebugInfo/dwarfdump-decompression-error.test @@ -0,0 +1,15 @@ +REQUIRES: zlib + +// dwarfdump-decompression-error.elf-x86-64 is prepared using following +// source code and invocation: +// test.cpp: +// int main() { return 0; } +// +// gcc test.cpp -o out -g -Wl,--compress-debug-sections,zlib +// +// After that result object was modified manually. One random byte in compressed +// content of .debug_info section was changed to 0xff. That breaks normal +// decompression flow in runtime. +RUN: llvm-dwarfdump %p/Inputs/dwarfdump-decompression-error.elf-x86-64 2>&1 | FileCheck %s + +CHECK: error: failed to decompress '.debug_info', zlib error: Z_DATA_ERROR |