From ce4a7239168aab6e323322248549b35f0ffb9917 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 9 Dec 2015 21:02:33 +0000 Subject: [PATCH] [llvm-dwp] Sink debug_types.dwo emission into the code parsing the type signatures (NFC) This is a preliminary change towards deduplicating type units based on their signatures. Next change will skip emission of types when their signature has already been seen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255154 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-dwp/llvm-dwp.cpp | 42 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/tools/llvm-dwp/llvm-dwp.cpp b/tools/llvm-dwp/llvm-dwp.cpp index 9a9440574e8..5d95a751f71 100644 --- a/tools/llvm-dwp/llvm-dwp.cpp +++ b/tools/llvm-dwp/llvm-dwp.cpp @@ -137,9 +137,14 @@ struct UnitIndexEntry { DWARFUnitIndex::Entry::SectionContribution Contributions[8]; }; -static void addAllTypes(std::vector &TypeIndexEntries, - uint32_t OutTypesOffset, StringRef Types, - const UnitIndexEntry &CUEntry) { +static void addAllTypes(MCStreamer &Out, + std::vector &TypeIndexEntries, + MCSection *OutputTypes, StringRef Types, + const UnitIndexEntry &CUEntry, uint32_t &TypesOffset) { + if (Types.empty()) + return; + + Out.SwitchSection(OutputTypes); uint32_t Offset = 0; DataExtractor Data(Types, true, 0); while (Data.isValidOffset(Offset)) { @@ -148,11 +153,14 @@ static void addAllTypes(std::vector &TypeIndexEntries, // Zero out the debug_info contribution Entry.Contributions[0] = {}; auto &C = Entry.Contributions[DW_SECT_TYPES - DW_SECT_INFO]; - C.Offset = OutTypesOffset + Offset; + C.Offset = TypesOffset + Offset; auto PrevOffset = Offset; // Length of the unit, including the 4 byte length field. C.Length = Data.getU32(&Offset) + 4; + Out.EmitBytes(Types.substr(Offset - 4, C.Length)); + TypesOffset += C.Length; + Data.getU16(&Offset); // Version Data.getU32(&Offset); // Abbrev offset Data.getU8(&Offset); // Address size @@ -184,8 +192,11 @@ static void writeIndex(MCStreamer &Out, MCSection *Section, for (size_t i = 0; i != IndexEntries.size(); ++i) { auto S = IndexEntries[i].Signature; auto H = S & Mask; - while (Buckets[H]) + while (Buckets[H]) { + assert(S != IndexEntries[Buckets[H] - 1].Signature && + "Duplicate type unit"); H += ((S >> 32) & Mask) | 1; + } Buckets[H] = i + 1; } @@ -220,6 +231,7 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { const auto &MCOFI = *Out.getContext().getObjectFileInfo(); MCSection *const StrSection = MCOFI.getDwarfStrDWOSection(); MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection(); + MCSection *const TypesSection = MCOFI.getDwarfTypesDWOSection(); const StringMap> KnownSections = { {"debug_info.dwo", {MCOFI.getDwarfInfoDWOSection(), DW_SECT_INFO}}, {"debug_types.dwo", {MCOFI.getDwarfTypesDWOSection(), DW_SECT_TYPES}}, @@ -247,11 +259,9 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { StringRef CurStrSection; StringRef CurStrOffsetSection; + StringRef CurTypesSection; StringRef InfoSection; StringRef AbbrevSection; - StringRef TypesSection; - - auto TypesOffset = ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]; for (const auto &Section : ErrOrObj->getBinary()->sections()) { StringRef Name; @@ -269,9 +279,11 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { if (DWARFSectionKind Kind = SectionPair->second.second) { auto Index = Kind - DW_SECT_INFO; - CurEntry.Contributions[Index].Offset = ContributionOffsets[Index]; - ContributionOffsets[Index] += - (CurEntry.Contributions[Index].Length = Contents.size()); + if (Kind != DW_SECT_TYPES) { + CurEntry.Contributions[Index].Offset = ContributionOffsets[Index]; + ContributionOffsets[Index] += + (CurEntry.Contributions[Index].Length = Contents.size()); + } switch (Kind) { case DW_SECT_INFO: @@ -280,9 +292,6 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { case DW_SECT_ABBREV: AbbrevSection = Contents; break; - case DW_SECT_TYPES: - TypesSection = Contents; - break; default: break; } @@ -293,6 +302,8 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { CurStrOffsetSection = Contents; else if (OutSection == StrSection) CurStrSection = Contents; + else if (OutSection == TypesSection) + CurTypesSection = Contents; else { Out.SwitchSection(OutSection); Out.EmitBytes(Contents); @@ -302,7 +313,8 @@ static std::error_code write(MCStreamer &Out, ArrayRef Inputs) { assert(!AbbrevSection.empty()); assert(!InfoSection.empty()); CurEntry.Signature = getCUSignature(AbbrevSection, InfoSection); - addAllTypes(TypeIndexEntries, TypesOffset, TypesSection, CurEntry); + addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection, CurEntry, + ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]); if (auto Err = writeStringsAndOffsets(Out, Strings, StringOffset, StrSection, StrOffsetSection, -- 2.34.1