[llvm] r329537 - [dsymutil] Don't crash on empty CU
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 8 10:35:17 PDT 2018
Author: jdevlieghere
Date: Sun Apr 8 10:35:17 2018
New Revision: 329537
URL: http://llvm.org/viewvc/llvm-project?rev=329537&view=rev
Log:
[dsymutil] Don't crash on empty CU
Add some additional checks so we don't crash on empty compile units.
Added:
llvm/trunk/test/tools/dsymutil/Inputs/empty-CU.o (with props)
llvm/trunk/test/tools/dsymutil/Inputs/empty-CU.s
llvm/trunk/test/tools/dsymutil/X86/empty-CU.test
Modified:
llvm/trunk/tools/dsymutil/DwarfLinker.cpp
Added: llvm/trunk/test/tools/dsymutil/Inputs/empty-CU.o
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/empty-CU.o?rev=329537&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/dsymutil/Inputs/empty-CU.o
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/dsymutil/Inputs/empty-CU.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/empty-CU.s?rev=329537&view=auto
==============================================================================
--- llvm/trunk/test/tools/dsymutil/Inputs/empty-CU.s (added)
+++ llvm/trunk/test/tools/dsymutil/Inputs/empty-CU.s Sun Apr 8 10:35:17 2018
@@ -0,0 +1,16 @@
+ .section __DWARF,__debug_info,regular,debug
+.long 8 # CU length
+.short 3 # Version
+.long 0 # Abbrev offset
+.byte 4 # AddrSize
+.byte 1 # Abbrev 1
+.long 7 # Unit lengthh...
+.short 3
+.long 0
+.byte 4
+ .section __DWARF,__debug_abbrev,regular,debug
+.byte 1 # Abbrev code
+.byte 0x11 # TAG_compile_unit
+.byte 0 # no children
+.byte 0 # no attributes
+.byte 0
Added: llvm/trunk/test/tools/dsymutil/X86/empty-CU.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/empty-CU.test?rev=329537&view=auto
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/empty-CU.test (added)
+++ llvm/trunk/test/tools/dsymutil/X86/empty-CU.test Sun Apr 8 10:35:17 2018
@@ -0,0 +1,7 @@
+RUN: dsymutil --update -f %p/../Inputs/empty-CU.o -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)
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=329537&r1=329536&r2=329537&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Sun Apr 8 10:35:17 2018
@@ -342,6 +342,10 @@ public:
Info.resize(OrigUnit.getNumDIEs());
auto CUDie = OrigUnit.getUnitDIE(false);
+ if (!CUDie) {
+ HasODR = false;
+ return;
+ }
if (auto Lang = dwarf::toUnsigned(CUDie.find(dwarf::DW_AT_language)))
HasODR = CanUseODR && (*Lang == dwarf::DW_LANG_C_plus_plus ||
*Lang == dwarf::DW_LANG_C_plus_plus_03 ||
@@ -4024,6 +4028,8 @@ Error DwarfLinker::loadClangModule(Strin
// Recursively get all modules imported by this one.
auto CUDie = CU->getUnitDIE(false);
+ if (!CUDie)
+ continue;
if (!registerModuleReference(CUDie, *CU, ModuleMap, DMO, Ranges, StringPool,
UniquingStringPool, ODRContexts, UnitID,
Indent)) {
@@ -4083,6 +4089,10 @@ void DwarfLinker::DIECloner::cloneAllCom
for (auto &CurrentUnit : CompileUnits) {
auto InputDIE = CurrentUnit->getOrigUnit().getUnitDIE();
CurrentUnit->setStartOffset(Linker.OutputDebugInfoSize);
+ if (!InputDIE) {
+ Linker.OutputDebugInfoSize = CurrentUnit->computeNextUnitOffset();
+ continue;
+ }
if (CurrentUnit->getInfo(0).Keep) {
// Clone the InputDIE into your Unit DIE in our compile unit since it
// already has a DIE inside of it.
@@ -4320,10 +4330,14 @@ bool DwarfLinker::link(const DebugMap &M
}
// Now build the DIE parent links that we will use during the next phase.
- for (auto &CurrentUnit : LinkContext.CompileUnits)
+ for (auto &CurrentUnit : LinkContext.CompileUnits) {
+ auto CUDie = CurrentUnit->getOrigUnit().getUnitDIE();
+ if (!CUDie)
+ continue;
analyzeContextInfo(CurrentUnit->getOrigUnit().getUnitDIE(), 0,
*CurrentUnit, &ODRContexts.getRoot(),
UniquingStringPool, ODRContexts);
+ }
std::unique_lock<std::mutex> LockGuard(ProcessedFilesMutex);
ProcessedFiles.set(i);
More information about the llvm-commits
mailing list