diff --git a/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo b/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo new file mode 100644 index 00000000000..26f276ad053 Binary files /dev/null and b/test/tools/llvm-dwp/Inputs/non_cu_top_level.dwo differ diff --git a/test/tools/llvm-dwp/X86/non_cu_top_level.test b/test/tools/llvm-dwp/X86/non_cu_top_level.test new file mode 100644 index 00000000000..60b8742cdc2 --- /dev/null +++ b/test/tools/llvm-dwp/X86/non_cu_top_level.test @@ -0,0 +1,3 @@ +RUN: not llvm-dwp %p/../Inputs/non_cu_top_level.dwo -o %t 2>&1 | FileCheck %s + +CHECK: error: top level DIE is not a compile unit diff --git a/tools/llvm-dwp/llvm-dwp.cpp b/tools/llvm-dwp/llvm-dwp.cpp index 5e83d7c9cac..31b2f63eb0a 100644 --- a/tools/llvm-dwp/llvm-dwp.cpp +++ b/tools/llvm-dwp/llvm-dwp.cpp @@ -141,9 +141,10 @@ static const char *getIndexedString(uint32_t Form, DataExtractor InfoData, return StrData.getCStr(&StrOffset); } -static CompileUnitIdentifiers getCUIdentifiers(StringRef Abbrev, StringRef Info, - StringRef StrOffsets, - StringRef Str) { +static Expected getCUIdentifiers(StringRef Abbrev, + StringRef Info, + StringRef StrOffsets, + StringRef Str) { uint32_t Offset = 0; DataExtractor InfoData(Info, true, 0); InfoData.getU32(&Offset); // Length @@ -156,9 +157,8 @@ static CompileUnitIdentifiers getCUIdentifiers(StringRef Abbrev, StringRef Info, DataExtractor AbbrevData(Abbrev, true, 0); uint32_t AbbrevOffset = getCUAbbrev(Abbrev, AbbrCode); uint64_t Tag = AbbrevData.getULEB128(&AbbrevOffset); - (void)Tag; - // FIXME: Real error handling - assert(Tag == dwarf::DW_TAG_compile_unit); + if (Tag != dwarf::DW_TAG_compile_unit) + return make_error("top level DIE is not a compile unit"); // DW_CHILDREN AbbrevData.getU8(&AbbrevOffset); uint32_t Name; @@ -506,11 +506,14 @@ static Error write(MCStreamer &Out, ArrayRef Inputs) { continue; auto P = IndexEntries.insert(std::make_pair(E.getSignature(), CurEntry)); - CompileUnitIdentifiers ID = getCUIdentifiers( + Expected EID = getCUIdentifiers( getSubsection(AbbrevSection, E, DW_SECT_ABBREV), getSubsection(InfoSection, E, DW_SECT_INFO), getSubsection(CurStrOffsetSection, E, DW_SECT_STR_OFFSETS), CurStrSection); + if (!EID) + return EID.takeError(); + const auto &ID = *EID; if (!P.second) return make_error(buildDuplicateError(*P.first, ID, Input)); auto &NewEntry = P.first->second; @@ -537,8 +540,11 @@ static Error write(MCStreamer &Out, ArrayRef Inputs) { ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); } } else { - CompileUnitIdentifiers ID = getCUIdentifiers( + Expected EID = getCUIdentifiers( AbbrevSection, InfoSection, CurStrOffsetSection, CurStrSection); + if (!EID) + return EID.takeError(); + const auto &ID = *EID; auto P = IndexEntries.insert(std::make_pair(ID.Signature, CurEntry)); if (!P.second) return make_error(buildDuplicateError(*P.first, ID, ""));