[ELF] - Make LLD remove gnu-lib compression prefix (".z") after decompression when using -r
This is PR33289.
Previously LLD leaved section naming as is and that lead to wrong result,
because we decompress sections when using -r,
and hence should remove ".z" prefix.
Differential revision: https://reviews.llvm.org/D33885
llvm-svn: 304711
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 79ca67e..4b36d88 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -93,6 +93,11 @@
} // anonymous namespace
StringRef elf::getOutputSectionName(StringRef Name) {
+ // ".zdebug_" is a prefix for ZLIB-compressed sections.
+ // Because we decompressed input sections, we want to remove 'z'.
+ if (Name.startswith(".zdebug_"))
+ return Saver.save("." + Name.substr(2));
+
if (Config->Relocatable)
return Name;
@@ -122,10 +127,6 @@
if (Name == "COMMON")
return ".bss";
- // ".zdebug_" is a prefix for ZLIB-compressed sections.
- // Because we decompressed input sections, we want to remove 'z'.
- if (Name.startswith(".zdebug_"))
- return Saver.save("." + Name.substr(2));
return Name;
}