diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp --- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp @@ -453,6 +453,11 @@ Twine(Sec.ChType) + ") of section '" + Sec.Name + "' is unsupported"); } + if (auto *Reason = + compression::getReasonIfUnsupported(compression::formatFor(Type))) + return createStringError(errc::invalid_argument, + "failed to decompress section '" + Sec.Name + + "': " + Reason); if (Error E = compression::decompress(Type, Compressed, Decompressed, static_cast(Sec.Size))) return createStringError(errc::invalid_argument, diff --git a/llvm/test/tools/llvm-objcopy/ELF/decompress-debug-sections-unsupported-zlib.test b/llvm/test/tools/llvm-objcopy/ELF/decompress-debug-sections-unsupported-zlib.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/ELF/decompress-debug-sections-unsupported-zlib.test @@ -0,0 +1,18 @@ +# UNSUPPORTED: zlib +# RUN: yaml2obj %s -o %t +# RUN: not llvm-objcopy --decompress-debug-sections %t /dev/null 2>&1 | FileCheck %s -DFILE=%t + +# CHECK: error: '[[FILE]]': failed to decompress section '.debug_info': LLVM was not built with LLVM_ENABLE_ZLIB or did not find zlib at build time + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Type: SHT_PROGBITS + Name: .debug_info + Flags: [ SHF_COMPRESSED ] + AddressAlign: 8 + Content: "010000000000000001000000000000000100000000000000789c63040000020002" diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp @@ -993,11 +993,6 @@ "--decompress-debug-sections"); } - if (Config.DecompressDebugSections && !compression::zlib::isAvailable()) - return createStringError( - errc::invalid_argument, - "LLVM was not compiled with LLVM_ENABLE_ZLIB: cannot decompress"); - if (Config.ExtractPartition && Config.ExtractMainPartition) return createStringError(errc::invalid_argument, "cannot specify --extract-partition together with "