From 23919372d1db1dba80e8c4697e0a0922e830fc3a Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Sat, 6 Feb 2016 01:15:26 +0000 Subject: [llvm-dwp] Merge cu_index from DWPs This is almost feature complete - just missing tu_index merging now. llvm-svn: 259971 --- llvm/tools/llvm-dwp/llvm-dwp.cpp | 43 ++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'llvm/tools/llvm-dwp/llvm-dwp.cpp') diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index 570854b849c..bf0d29f4c2d 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -24,6 +24,7 @@ #include #include #include +#include using namespace llvm; using namespace llvm::object; @@ -239,6 +240,7 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { MCSection *const StrSection = MCOFI.getDwarfStrDWOSection(); MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection(); MCSection *const TypesSection = MCOFI.getDwarfTypesDWOSection(); + MCSection *const CUIndexSection = MCOFI.getDwarfCUIndexSection(); const StringMap> KnownSections = { {"debug_info.dwo", {MCOFI.getDwarfInfoDWOSection(), DW_SECT_INFO}}, {"debug_types.dwo", {MCOFI.getDwarfTypesDWOSection(), DW_SECT_TYPES}}, @@ -246,7 +248,9 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { {"debug_str.dwo", {StrSection, static_cast(0)}}, {"debug_loc.dwo", {MCOFI.getDwarfLocDWOSection(), DW_SECT_LOC}}, {"debug_line.dwo", {MCOFI.getDwarfLineDWOSection(), DW_SECT_LINE}}, - {"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}}}; + {"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}}, + {"debug_cu_index", + {MCOFI.getDwarfCUIndexSection(), static_cast(0)}}}; std::vector IndexEntries; std::vector TypeIndexEntries; @@ -261,14 +265,14 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { if (!ErrOrObj) return ErrOrObj.getError(); - IndexEntries.emplace_back(); - UnitIndexEntry &CurEntry = IndexEntries.back(); + UnitIndexEntry CurEntry = {}; StringRef CurStrSection; StringRef CurStrOffsetSection; StringRef CurTypesSection; StringRef InfoSection; StringRef AbbrevSection; + StringRef CurCUIndexSection; for (const auto &Section : ErrOrObj->getBinary()->sections()) { StringRef Name; @@ -311,6 +315,8 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { CurStrSection = Contents; else if (OutSection == TypesSection) CurTypesSection = Contents; + else if (OutSection == CUIndexSection) + CurCUIndexSection = Contents; else { Out.SwitchSection(OutSection); Out.EmitBytes(Contents); @@ -319,9 +325,34 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { assert(!AbbrevSection.empty()); assert(!InfoSection.empty()); - CurEntry.Signature = getCUSignature(AbbrevSection, InfoSection); - addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection, CurEntry, - ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); + if (!CurCUIndexSection.empty()) { + DWARFUnitIndex CUIndex(DW_SECT_INFO); + DataExtractor CUIndexData(CurCUIndexSection, + ErrOrObj->getBinary()->isLittleEndian(), 0); + if (!CUIndex.parse(CUIndexData)) + return make_error_code(std::errc::invalid_argument); + + for (const DWARFUnitIndex::Entry &E : CUIndex.getRows()) { + auto NewEntry = CurEntry; + auto *I = E.getOffsets(); + if (!I) + continue; + NewEntry.Signature = E.getSignature(); + for (auto Kind : CUIndex.getColumnKinds()) { + auto &C = NewEntry.Contributions[Kind - DW_SECT_INFO]; + C.Offset += I->Offset; + C.Length = I->Length; + ++I; + } + IndexEntries.push_back(NewEntry); + } + } else { + CurEntry.Signature = getCUSignature(AbbrevSection, InfoSection); + addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection, + CurEntry, ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); + + IndexEntries.push_back(CurEntry); + } if (auto Err = writeStringsAndOffsets(Out, Strings, StringOffset, StrSection, StrOffsetSection, -- cgit v1.2.3