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

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 5 01:29:16 PDT 2017


grimar created this revision.
Herald added a subscriber: emaste.

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.


https://reviews.llvm.org/D33885

Files:
  ELF/Writer.cpp
  test/ELF/relocatable-compressed-input.s


Index: test/ELF/relocatable-compressed-input.s
===================================================================
--- test/ELF/relocatable-compressed-input.s
+++ test/ELF/relocatable-compressed-input.s
@@ -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"
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ 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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33885.101375.patch
Type: text/x-patch
Size: 2353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170605/3aef3a98/attachment.bin>


More information about the llvm-commits mailing list