[llvm] r254441 - [llvm-dwp] Deduplicate strings in the debug_str.dwo section

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 1 11:17:59 PST 2015


Author: dblaikie
Date: Tue Dec  1 13:17:58 2015
New Revision: 254441

URL: http://llvm.org/viewvc/llvm-project?rev=254441&view=rev
Log:
[llvm-dwp] Deduplicate strings in the debug_str.dwo section

Also, ensure that references to those strings in debug_str_offsets.dwo
correctly refer to the deduplicated strings.

Modified:
    llvm/trunk/test/tools/llvm-dwp/X86/simple.test
    llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp

Modified: llvm/trunk/test/tools/llvm-dwp/X86/simple.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/simple.test?rev=254441&r1=254440&r2=254441&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/simple.test (original)
+++ llvm/trunk/test/tools/llvm-dwp/X86/simple.test Tue Dec  1 13:17:58 2015
@@ -46,13 +46,11 @@ FIXME: Emit and verify the cu_index cont
 CHECK: .debug_str.dwo contents:
 CHECK: "clang version
 CHECK: 0x[[ACPP:.*]]: "a.cpp"
-FIXME: Remove duplicates
-CHECK: 0x[[SECONDREV:.*]]: "clang version
+CHECK-NOT: "clang version
 CHECK: 0x[[BCPP:.*]]: "b.cpp"
 
 CHECK: .debug_str_offsets.dwo contents:
 CHECK: : 00000000
 CHECK: : [[ACPP]]
-CHECK: : [[SECONDREV]]
-FIXME: Update str offset indexes, this should be BCPP \/
+CHECK: : 00000000
 CHECK: : [[BCPP]]

Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=254441&r1=254440&r2=254441&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Tue Dec  1 13:17:58 2015
@@ -40,8 +40,9 @@ static int error(const Twine &Error, con
 
 static std::error_code
 writeStringsAndOffsets(MCStreamer &Out, StringMap<uint32_t> &Strings,
-                       uint32_t &StringOffset, MCSection *StrOffsetSection,
-                       StringRef CurStrSection, StringRef CurStrOffsetSection) {
+                       uint32_t &StringOffset, MCSection *StrSection,
+                       MCSection *StrOffsetSection, StringRef CurStrSection,
+                       StringRef CurStrOffsetSection) {
   // Could possibly produce an error or warning if one of these was non-null but
   // the other was null.
   if (CurStrSection.empty() || CurStrOffsetSection.empty())
@@ -54,9 +55,14 @@ writeStringsAndOffsets(MCStreamer &Out,
   uint32_t PrevOffset = 0;
   while (const char *s = Data.getCStr(&LocalOffset)) {
     StringRef Str(s, LocalOffset - PrevOffset - 1);
-    OffsetRemapping[PrevOffset] = StringOffset;
-    // insert, if successful, write new string to the str.dwo section
-    StringOffset += Str.size() + 1;
+    auto Pair = Strings.insert(std::make_pair(Str, StringOffset));
+    if (Pair.second) {
+      Out.SwitchSection(StrSection);
+      Out.EmitBytes(
+          StringRef(Pair.first->getKeyData(), Pair.first->getKeyLength() + 1));
+      StringOffset += Str.size() + 1;
+    }
+    OffsetRemapping[PrevOffset] = Pair.first->second;
     PrevOffset = LocalOffset;
   }
 
@@ -106,19 +112,19 @@ static std::error_code write(MCStreamer
         StringRef Contents;
         if (auto Err = Section.getContents(Contents))
           return Err;
-        if (OutSection == StrOffsetSection) {
+        if (OutSection == StrOffsetSection)
           CurStrOffsetSection = Contents;
-          continue;
-        }
-        if (OutSection == StrSection)
+        else if (OutSection == StrSection)
           CurStrSection = Contents;
-        Out.SwitchSection(OutSection);
-        Out.EmitBytes(Contents);
+        else {
+          Out.SwitchSection(OutSection);
+          Out.EmitBytes(Contents);
+        }
       }
     }
-    if (auto Err =
-            writeStringsAndOffsets(Out, Strings, StringOffset, StrOffsetSection,
-                                   CurStrSection, CurStrOffsetSection))
+    if (auto Err = writeStringsAndOffsets(Out, Strings, StringOffset,
+                                          StrSection, StrOffsetSection,
+                                          CurStrSection, CurStrOffsetSection))
       return Err;
   }
   return std::error_code();




More information about the llvm-commits mailing list