]> granicus.if.org Git - llvm/commitdiff
[dsymutil] Don't clone empty CUs
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 13 Feb 2019 00:32:06 +0000 (00:32 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 13 Feb 2019 00:32:06 +0000 (00:32 +0000)
The DWARF standard says that an empty compile unit is not valid:

> Each such contribution consists of a compilation unit header (see
> Section 7.5.1.1 on page 200) followed by a single DW_TAG_compile_unit or
> DW_TAG_partial_unit debugging information entry, together with its
> children.

Therefore we shouldn't clone them in dsymutil.

Differential revision: https://reviews.llvm.org/D57979

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353903 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/dsymutil/X86/empty-CU.test
test/tools/dsymutil/X86/generate-empty-CU.test
tools/dsymutil/CompileUnit.cpp
tools/dsymutil/DwarfLinker.cpp

index c55a3ca8659eab7b14df2a7e7814822989eaae06..e2acefcdccfd2b0f956a7e217d213f6cbbe7aecd 100644 (file)
@@ -4,4 +4,3 @@ 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)
index 5b1dd75159354bede5bd990acd433aed1bc38d59..02914181b3356d19bf85f62080e44aca7c578144 100644 (file)
@@ -1,8 +1,8 @@
 # RUN: dsymutil -f -o - -oso-prepend-path=%p/.. -y %s | llvm-dwarfdump -v - | FileCheck %s
 
 # This test on links the Dwarf for an LTO binary and on purpose doesn't retain
-# any symbol in the second CU out of 3. This is the only case where dsymutil
-# will generate an empty CU and it requires special handling.
+# any symbol in the second CU out of 3. To be valid DWARF ssymutil must not
+# generate an empty CU but omit it.
 
 ---
 triple:          'x86_64-apple-darwin'
@@ -22,9 +22,7 @@ CHECK:        DW_AT_name {{.*}} "basic1.c"
 CHECK:   DW_TAG_subprogram
                 DW_AT_name {{.*}} "main"
 
-CHECK: Compile Unit: length = 0x00000007 version = 0x0002 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x0000008c)
-
-CHECK: Compile Unit: length = 0x00000089 version = 0x0002 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x00000119)
+CHECK: 0x00000081: Compile Unit: length = 0x00000089 version = 0x0002 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x0000010e)
 
 CHECK: DW_TAG_compile_unit
 CHECK:        DW_AT_name {{.*}} "basic3.c"
index 3eb6abbb852d20fce110b39b80683e3234c7d6d2..670591a9436f95b4a1df7bf75746f9c2bb886d7f 100644 (file)
@@ -55,12 +55,11 @@ void CompileUnit::markEverythingAsKept() {
 }
 
 uint64_t CompileUnit::computeNextUnitOffset() {
-  NextUnitOffset = StartOffset + 11 /* Header size */;
-  // The root DIE might be null, meaning that the Unit had nothing to
-  // contribute to the linked output. In that case, we will emit the
-  // unit header without any actual DIE.
-  if (NewUnit)
+  NextUnitOffset = StartOffset;
+  if (NewUnit) {
+    NextUnitOffset += 11 /* Header size */;
     NextUnitOffset += NewUnit->getUnitDie().getSize();
+  }
   return NextUnitOffset;
 }
 
index 384805808e5e2adec18451524b1cc21498a0ddf9..ce8653173c3c852a4daadc99f9517eed2d6dc306 100644 (file)
@@ -2266,10 +2266,10 @@ void DwarfLinker::DIECloner::cloneAllCompileUnits(
     if (LLVM_LIKELY(!Linker.Options.Update))
       Linker.generateUnitRanges(*CurrentUnit);
     CurrentUnit->fixupForwardReferences();
-    Linker.Streamer->emitCompileUnitHeader(*CurrentUnit);
-    if (!CurrentUnit->getOutputUnitDIE())
-      continue;
-    Linker.Streamer->emitDIE(*CurrentUnit->getOutputUnitDIE());
+    if (CurrentUnit->getOutputUnitDIE()) {
+      Linker.Streamer->emitCompileUnitHeader(*CurrentUnit);
+      Linker.Streamer->emitDIE(*CurrentUnit->getOutputUnitDIE());
+    }
   }
 }