[PATCH] D57979: [dsymutil] Don't clone empty CUs

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 8 14:39:00 PST 2019


JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, friss.
Herald added a project: LLVM.
JDevlieghere retitled this revision from "[dsymutil] Update unobfuscation logic." to "[dsymutil] Don't clone empty CUs".

The DWARF standard says that an empty compile unit is not valid:

> Each such contribution consists of a type unit header (see Section 7.5.1.3 on page 202) followed by a DW_TAG_type_unit entry, together with its children.

Therefore we shouldn't clone them in dsymutil.


Repository:
  rL LLVM

https://reviews.llvm.org/D57979

Files:
  llvm/test/tools/dsymutil/X86/empty-CU.test
  llvm/tools/dsymutil/CompileUnit.h
  llvm/tools/dsymutil/DwarfLinker.cpp


Index: llvm/tools/dsymutil/DwarfLinker.cpp
===================================================================
--- llvm/tools/dsymutil/DwarfLinker.cpp
+++ llvm/tools/dsymutil/DwarfLinker.cpp
@@ -2208,8 +2208,7 @@
       Unit->markEverythingAsKept();
     }
   }
-  if (!Unit->getOrigUnit().getUnitDIE().hasChildren())
-    return Error::success();
+
   if (!Quiet && Options.Verbose) {
     outs().indent(Indent);
     outs() << "cloning .debug_info from " << Filename << "\n";
@@ -2229,6 +2228,9 @@
     return;
 
   for (auto &CurrentUnit : CompileUnits) {
+    if (!*CurrentUnit)
+      continue;
+
     auto InputDIE = CurrentUnit->getOrigUnit().getUnitDIE();
     CurrentUnit->setStartOffset(Linker.OutputDebugInfoSize);
     if (!InputDIE) {
@@ -2263,6 +2265,9 @@
 
   // Emit all the compile unit's debug information.
   for (auto &CurrentUnit : CompileUnits) {
+    if (!*CurrentUnit)
+      continue;
+
     if (LLVM_LIKELY(!Linker.Options.Update))
       Linker.generateUnitRanges(*CurrentUnit);
     CurrentUnit->fixupForwardReferences();
Index: llvm/tools/dsymutil/CompileUnit.h
===================================================================
--- llvm/tools/dsymutil/CompileUnit.h
+++ llvm/tools/dsymutil/CompileUnit.h
@@ -112,6 +112,13 @@
     return nullptr;
   }
 
+  operator bool() const {
+    auto UnitDIE = getOrigUnit().getUnitDIE();
+    if (UnitDIE)
+      return UnitDIE.hasChildren();
+    return false;
+  }
+
   bool hasODR() const { return HasODR; }
   bool isClangModule() const { return !ClangModuleName.empty(); }
   const std::string &getClangModuleName() const { return ClangModuleName; }
Index: llvm/test/tools/dsymutil/X86/empty-CU.test
===================================================================
--- llvm/test/tools/dsymutil/X86/empty-CU.test
+++ llvm/test/tools/dsymutil/X86/empty-CU.test
@@ -1,7 +1,4 @@
-RUN: dsymutil --update -f %p/../Inputs/empty-CU.o -o - | llvm-dwarfdump -v - -debug-info | FileCheck %s
+RUN: dsymutil --update -f %p/../Inputs/empty-CU.o -verify -o - | llvm-dwarfdump -v - -debug-info  | FileCheck %s
 
 CHECK: .debug_info contents:
-CHECK: 0x00000000: Compile Unit: length = 0x00000008 version = 0x0003 abbr_offset = 0x0000 addr_size = 0x04 (next unit at 0x0000000c)
-
-CHECK: 0x0000000b: DW_TAG_compile_unit [1]
-CHECK: 0x0000000c: Compile Unit: length = 0x00000007 version = 0x0003 abbr_offset = 0x0000 addr_size = 0x04 (next unit at 0x00000017)
+CHECK-NOT: Compile Unit


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57979.186051.patch
Type: text/x-patch
Size: 2446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190208/ab275328/attachment.bin>


More information about the llvm-commits mailing list