[lld] r304711 - [ELF] - Make LLD remove gnu-lib compression prefix (".z") after decompression when using -r

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 5 05:49:21 PDT 2017


Author: grimar
Date: Mon Jun  5 07:49:21 2017
New Revision: 304711

URL: http://llvm.org/viewvc/llvm-project?rev=304711&view=rev
Log:
[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

Added:
    lld/trunk/test/ELF/relocatable-compressed-input.s
Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=304711&r1=304710&r2=304711&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Jun  5 07:49:21 2017
@@ -93,6 +93,11 @@ private:
 } // 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 @@ StringRef elf::getOutputSectionName(Stri
   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;
 }
 

Added: lld/trunk/test/ELF/relocatable-compressed-input.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-compressed-input.s?rev=304711&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-compressed-input.s (added)
+++ lld/trunk/test/ELF/relocatable-compressed-input.s Mon Jun  5 07:49:21 2017
@@ -0,0 +1,45 @@
+# REQUIRES: zlib
+
+# RUN: llvm-mc -compress-debug-sections=zlib-gnu -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
+# RUN: llvm-readobj -sections %t1 | FileCheck -check-prefix=GNU %s
+# GNU: Name: .zdebug_str
+
+# RUN: ld.lld %t1 -o %t2 -r
+# RUN: llvm-readobj -sections -section-data %t2 | FileCheck %s
+
+## Check we decompress section and remove ".z" prefix specific for zlib-gnu compression.
+# CHECK:      Section {
+# CHECK:        Index:
+# CHECK:        Name: .debug_str
+# CHECK-NEXT:   Type: SHT_PROGBITS
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_MERGE
+# CHECK-NEXT:     SHF_STRINGS
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address:
+# CHECK-NEXT:   Offset:
+# CHECK-NEXT:   Size:
+# CHECK-NEXT:   Link:
+# CHECK-NEXT:   Info:
+# CHECK-NEXT:   AddressAlignment: 1
+# CHECK-NEXT:   EntrySize: 1
+# CHECK-NEXT:   SectionData (
+# CHECK-NEXT:     0000: {{.*}}  |short unsigned i|
+# CHECK-NEXT:     0010: {{.*}}  |nt.unsigned int.|
+# CHECK-NEXT:     0020: {{.*}}  |long unsigned in|
+# CHECK-NEXT:     0030: {{.*}}  |t.char.unsigned |
+# CHECK-NEXT:     0040: {{.*}}  |char.|
+# CHECK-NEXT:   )
+# CHECK-NEXT: }
+
+.section .debug_str,"MS", at progbits,1
+.LASF2:
+ .string "short unsigned int"
+.LASF3:
+ .string "unsigned int"
+.LASF0:
+ .string "long unsigned int"
+.LASF8:
+ .string "char"
+.LASF1:
+ .string "unsigned char"




More information about the llvm-commits mailing list