Support GNU-style ZLIB-compressed input sections.
Previously, we supported only SHF_COMPRESSED sections because it's
new and it's the ELF standard. But there are object files compressed
in the GNU style out there, so we had to support it.
Sections compressed in the GNU style start with ".zdebug_" and
contain different headers than the ELF standard's one. In this
patch, getRawCompressedData is responsible to handle it.
A tricky thing about GNU-style compressed sections is that we have
to rename them when creating output sections. ".zdebug_" prefix
implies the section is compressed. We need to rename ".zdebug_"
".debug" because our output sections are not compressed.
We do that in this patch.
llvm-svn: 284068
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index d50deae..ade3ead7 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -91,7 +91,7 @@
};
} // anonymous namespace
-StringRef elf::getOutputSectionName(StringRef Name) {
+StringRef elf::getOutputSectionName(StringRef Name, BumpPtrAllocator &Alloc) {
if (Config->Relocatable)
return Name;
@@ -103,6 +103,11 @@
if (Name.startswith(V) || Name == Prefix)
return Prefix;
}
+
+ // ".zdebug_" is a prefix for ZLIB-compressed sections.
+ // Because we decompressed input sections, we want to remove 'z'.
+ if (Name.startswith(".zdebug_"))
+ return StringSaver(Alloc).save(Twine(".") + Name.substr(2));
return Name;
}
@@ -699,7 +704,8 @@
}
OutputSectionBase<ELFT> *Sec;
bool IsNew;
- std::tie(Sec, IsNew) = Factory.create(IS, getOutputSectionName(IS->Name));
+ StringRef OutsecName = getOutputSectionName(IS->Name, Alloc);
+ std::tie(Sec, IsNew) = Factory.create(IS, OutsecName);
if (IsNew)
OutputSections.push_back(Sec);
Sec->addSection(IS);