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 @@ -4,4 +4,3 @@ 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: llvm/test/tools/dsymutil/X86/generate-empty-CU.test =================================================================== --- llvm/test/tools/dsymutil/X86/generate-empty-CU.test +++ llvm/test/tools/dsymutil/X86/generate-empty-CU.test @@ -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. Dsymutil should not generate an empty +# CU and it. --- triple: 'x86_64-apple-darwin' @@ -22,9 +22,7 @@ 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: llvm/tools/dsymutil/CompileUnit.cpp =================================================================== --- llvm/tools/dsymutil/CompileUnit.cpp +++ llvm/tools/dsymutil/CompileUnit.cpp @@ -55,12 +55,11 @@ } 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: llvm/tools/dsymutil/DwarfLinker.cpp =================================================================== --- llvm/tools/dsymutil/DwarfLinker.cpp +++ llvm/tools/dsymutil/DwarfLinker.cpp @@ -2208,8 +2208,10 @@ Unit->markEverythingAsKept(); } } + if (!Unit->getOrigUnit().getUnitDIE().hasChildren()) return Error::success(); + if (!Quiet && Options.Verbose) { outs().indent(Indent); outs() << "cloning .debug_info from " << Filename << "\n"; @@ -2251,11 +2253,13 @@ // actually exist in the DIE tree. if (LLVM_LIKELY(!Linker.Options.Update) || Linker.Options.Translator) Linker.patchLineTableForUnit(*CurrentUnit, DwarfContext, Ranges, DMO); + Linker.emitAcceleratorEntriesForUnit(*CurrentUnit); - if (Linker.Options.Update) - continue; - Linker.patchRangesForUnit(*CurrentUnit, DwarfContext, DMO); - Linker.Streamer->emitLocationsForUnit(*CurrentUnit, DwarfContext); + + if (LLVM_LIKELY(!Linker.Options.Update)) { + Linker.patchRangesForUnit(*CurrentUnit, DwarfContext, DMO); + Linker.Streamer->emitLocationsForUnit(*CurrentUnit, DwarfContext); + } } if (Linker.Options.NoOutput) @@ -2266,10 +2270,10 @@ 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()); + } } }