[llvm] r261072 - llvm-dwp: Support for type units when merging DWPs into larger DWPs
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 16 23:00:25 PST 2016
Author: dblaikie
Date: Wed Feb 17 01:00:24 2016
New Revision: 261072
URL: http://llvm.org/viewvc/llvm-project?rev=261072&view=rev
Log:
llvm-dwp: Support for type units when merging DWPs into larger DWPs
Modified:
llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test
llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
Modified: llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test?rev=261072&r1=261071&r2=261072&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test (original)
+++ llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test Wed Feb 17 01:00:24 2016
@@ -1,5 +1,8 @@
RUN: llvm-dwp %p/../Inputs/type_dedup/a.dwo %p/../Inputs/type_dedup/b.dwo -o %t
RUN: llvm-dwarfdump %t | FileCheck %s
+RUN: llvm-dwp %p/../Inputs/type_dedup/b.dwo -o %T/b.dwp
+RUN: llvm-dwp %p/../Inputs/type_dedup/a.dwo %T/b.dwp -o %t
+RUN: llvm-dwarfdump %t | FileCheck %s
a.cpp:
struct common { };
Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=261072&r1=261071&r2=261072&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Wed Feb 17 01:00:24 2016
@@ -139,6 +139,41 @@ struct UnitIndexEntry {
DWARFUnitIndex::Entry::SectionContribution Contributions[8];
};
+static void addAllTypesFromDWP(MCStreamer &Out,
+ std::vector<UnitIndexEntry> &TypeIndexEntries,
+ const DWARFUnitIndex &TUIndex,
+ MCSection *OutputTypes, StringRef Types,
+ const UnitIndexEntry &TUEntry,
+ uint32_t &TypesOffset) {
+ Out.SwitchSection(OutputTypes);
+ for (const DWARFUnitIndex::Entry &E : TUIndex.getRows()) {
+ auto *I = E.getOffsets();
+ if (!I)
+ continue;
+ if (any_of(TypeIndexEntries, [&](const UnitIndexEntry &OldEntry) {
+ return OldEntry.Signature == E.getSignature();
+ }))
+ continue;
+ auto Entry = TUEntry;
+ Entry.Signature = E.getSignature();
+ // Zero out the debug_info contribution
+ Entry.Contributions[0] = {};
+ for (auto Kind : TUIndex.getColumnKinds()) {
+ auto &C = Entry.Contributions[Kind - DW_SECT_INFO];
+ C.Offset += I->Offset;
+ C.Length = I->Length;
+ ++I;
+ }
+ auto &C = Entry.Contributions[DW_SECT_TYPES - DW_SECT_INFO];
+ Out.EmitBytes(Types.substr(
+ C.Offset - TUEntry.Contributions[DW_SECT_TYPES - DW_SECT_INFO].Offset,
+ C.Length));
+ C.Offset = TypesOffset;
+ TypesOffset += C.Length;
+ TypeIndexEntries.push_back(Entry);
+ }
+}
+
static void addAllTypes(MCStreamer &Out,
std::vector<UnitIndexEntry> &TypeIndexEntries,
MCSection *OutputTypes, StringRef Types,
@@ -241,6 +276,7 @@ static std::error_code write(MCStreamer
MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection();
MCSection *const TypesSection = MCOFI.getDwarfTypesDWOSection();
MCSection *const CUIndexSection = MCOFI.getDwarfCUIndexSection();
+ MCSection *const TUIndexSection = MCOFI.getDwarfTUIndexSection();
const StringMap<std::pair<MCSection *, DWARFSectionKind>> KnownSections = {
{"debug_info.dwo", {MCOFI.getDwarfInfoDWOSection(), DW_SECT_INFO}},
{"debug_types.dwo", {MCOFI.getDwarfTypesDWOSection(), DW_SECT_TYPES}},
@@ -249,8 +285,8 @@ static std::error_code write(MCStreamer
{"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_cu_index",
- {MCOFI.getDwarfCUIndexSection(), static_cast<DWARFSectionKind>(0)}}};
+ {"debug_cu_index", {CUIndexSection, static_cast<DWARFSectionKind>(0)}},
+ {"debug_tu_index", {TUIndexSection, static_cast<DWARFSectionKind>(0)}}};
std::vector<UnitIndexEntry> IndexEntries;
std::vector<UnitIndexEntry> TypeIndexEntries;
@@ -273,6 +309,7 @@ static std::error_code write(MCStreamer
StringRef InfoSection;
StringRef AbbrevSection;
StringRef CurCUIndexSection;
+ StringRef CurTUIndexSection;
for (const auto &Section : ErrOrObj->getBinary()->sections()) {
StringRef Name;
@@ -317,6 +354,8 @@ static std::error_code write(MCStreamer
CurTypesSection = Contents;
else if (OutSection == CUIndexSection)
CurCUIndexSection = Contents;
+ else if (OutSection == TUIndexSection)
+ CurTUIndexSection = Contents;
else {
Out.SwitchSection(OutSection);
Out.EmitBytes(Contents);
@@ -346,6 +385,19 @@ static std::error_code write(MCStreamer
}
IndexEntries.push_back(NewEntry);
}
+
+ if (!CurTypesSection.empty()) {
+ if (CurTUIndexSection.empty())
+ return make_error_code(std::errc::invalid_argument);
+ DWARFUnitIndex TUIndex(DW_SECT_TYPES);
+ DataExtractor TUIndexData(CurTUIndexSection,
+ ErrOrObj->getBinary()->isLittleEndian(), 0);
+ if (!TUIndex.parse(TUIndexData))
+ return make_error_code(std::errc::invalid_argument);
+ addAllTypesFromDWP(Out, TypeIndexEntries, TUIndex, TypesSection,
+ CurTypesSection, CurEntry,
+ ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]);
+ }
} else {
CurEntry.Signature = getCUSignature(AbbrevSection, InfoSection);
addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection,
More information about the llvm-commits
mailing list