[llvm-objcopy] - Simplify `isCompressable` and fix the issue relative.
When --compress-debug-sections is given, llvm-objcopy do not compress
sections that have "ZLIB" header in data. Normally this signature is used
in zlib-gnu compression format. But if zlib-gnu used then the name of the compressed
section should start from .z* (e.g .zdebug_info). If it does not, then it is not
a zlib-gnu format and section should be treated as a normal uncompressed section.
Differential revision: https://reviews.llvm.org/D58908
llvm-svn: 355399
diff --git a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
index 1132aa1..6f21db9 100644
--- a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -223,18 +223,9 @@
return createStringError(object_error::parse_failed, "Section not found");
}
-static bool isCompressed(const SectionBase &Section) {
- const char *Magic = "ZLIB";
- return StringRef(Section.Name).startswith(".zdebug") ||
- (Section.OriginalData.size() > strlen(Magic) &&
- !strncmp(reinterpret_cast<const char *>(Section.OriginalData.data()),
- Magic, strlen(Magic))) ||
- (Section.Flags & ELF::SHF_COMPRESSED);
-}
-
static bool isCompressable(const SectionBase &Section) {
- return !isCompressed(Section) && isDebugSection(Section) &&
- Section.Name != ".gdb_index";
+ return !(Section.Flags & ELF::SHF_COMPRESSED) &&
+ StringRef(Section.Name).startswith(".debug");
}
static void replaceDebugSections(