Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 2060375

Browse files
committed
[llvm-dwp] Merge cu_index from DWPs
This is almost feature complete - just missing tu_index merging now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259971 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8192ebb commit 2060375

File tree

5 files changed

+96
-6
lines changed

5 files changed

+96
-6
lines changed

include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H
1111
#define LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H
1212

13+
#include "llvm/ADT/ArrayRef.h"
1314
#include "llvm/Support/DataExtractor.h"
1415
#include "llvm/Support/Format.h"
1516
#include "llvm/Support/raw_ostream.h"
@@ -56,6 +57,10 @@ class DWARFUnitIndex {
5657
public:
5758
const SectionContribution *getOffset(DWARFSectionKind Sec) const;
5859
const SectionContribution *getOffset() const;
60+
const SectionContribution *getOffsets() const {
61+
return Contributions.get();
62+
}
63+
uint64_t getSignature() const { return Signature; }
5964
};
6065

6166
private:
@@ -75,6 +80,12 @@ class DWARFUnitIndex {
7580
: InfoColumnKind(InfoColumnKind) {}
7681
void dump(raw_ostream &OS) const;
7782
const Entry *getFromOffset(uint32_t Offset) const;
83+
ArrayRef<DWARFSectionKind> getColumnKinds() const {
84+
return makeArrayRef(ColumnKinds.get(), Header.NumColumns);
85+
}
86+
ArrayRef<Entry> getRows() const {
87+
return makeArrayRef(Rows.get(), Header.NumBuckets);
88+
}
7889
};
7990
}
8091

1.35 KB
Binary file not shown.
1.23 KB
Binary file not shown.

test/tools/llvm-dwp/X86/merge.test

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
RUN: llvm-dwp %p/../Inputs/merge/notypes/c.dwo %p/../Inputs/merge/notypes/ab.dwp -o %t
2+
RUN: llvm-dwarfdump %t | FileCheck --check-prefix=CHECK --check-prefix=NOTYP %s
3+
4+
FIXME: For some reason, piping straight from llvm-dwp to llvm-dwarfdump doesn't behave well - looks like dwarfdump is reading/closes before dwp has finished.
5+
6+
DWP from a DWO (c.dwo) and a DWP (ab.dwp, created from a.dwo and b.dwo)
7+
Make sure the entries for A and B are updated correctly when read/processed from ab.dwp
8+
a.cpp:
9+
struct foo { };
10+
foo a;
11+
12+
b.cpp:
13+
struct bar { };
14+
void b(bar) {
15+
}
16+
17+
c.cpp:
18+
typedef int baz;
19+
baz c() {
20+
}
21+
22+
CHECK-LABEL: .debug_abbrev.dwo contents:
23+
CHECK-LABEL: Abbrev table for offset:
24+
CHECK: 0x0000[[CAOFF:.*]]
25+
CHECK-LABEL: Abbrev table for offset:
26+
CHECK: 0x0000[[AAOFF:.*]]
27+
CHECK-LABEL: Abbrev table for offset:
28+
CHECK: 0x0000[[BAOFF:.*]]
29+
30+
CHECK: .debug_info.dwo contents:
31+
CHECK: [[COFF:0x[0-9a-f]*]]:
32+
CHECK-LABEL: Compile Unit: length = {{.*}} version = 0x0004 abbr_offset =
33+
CHECK: 0x[[CAOFF]] addr_size = 0x08 (next unit at [[AOFF:.*]])
34+
CHECK: DW_AT_GNU_dwo_id {{.*}} ([[DWOC:.*]])
35+
CHECK: [[AOFF]]:
36+
CHECK-LABEL: Compile Unit: length = {{.*}} version = 0x0004 abbr_offset =
37+
CHECK: 0x[[AAOFF]] addr_size = 0x08 (next unit at [[BOFF:.*]])
38+
CHECK: DW_AT_GNU_dwo_id {{.*}} ([[DWOA:.*]])
39+
CHECK: [[BOFF]]:
40+
CHECK-LABEL: Compile Unit: length = {{.*}} version = 0x0004 abbr_offset =
41+
CHECK: 0x[[BAOFF]] addr_size = 0x08 (next unit at [[XOFF:.*]])
42+
CHECK: DW_AT_GNU_dwo_id {{.*}} ([[DWOB:.*]])
43+
44+
CHECK-LABEL: .debug_cu_index
45+
CHECK: Index Signature INFO ABBREV LINE STR_OFFSETS
46+
CHECK-DAG: [[DWOC]] {{\[}}[[COFF]], [[AOFF]]) [0x0000[[CAOFF]], 0x0000[[AAOFF]]) [0x00000000, 0x00000011) [0x00000000, 0x00000018)
47+
CHECK-DAG: [[DWOA]] {{\[}}[[AOFF]], [[BOFF]]) [0x0000[[AAOFF]], 0x0000[[BAOFF]]) [0x00000011, 0x00000022) [0x00000018, 0x00000028)
48+
CHECK-DAG: [[DWOB]] {{\[}}[[BOFF]], [[XOFF]]) [0x0000[[BAOFF]], 0x000000c3) [0x00000022, 0x00000033) [0x00000028, 0x0000003c)

tools/llvm-dwp/llvm-dwp.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <list>
2525
#include <memory>
2626
#include <unordered_set>
27+
#include <system_error>
2728

2829
using namespace llvm;
2930
using namespace llvm::object;
@@ -239,14 +240,17 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
239240
MCSection *const StrSection = MCOFI.getDwarfStrDWOSection();
240241
MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection();
241242
MCSection *const TypesSection = MCOFI.getDwarfTypesDWOSection();
243+
MCSection *const CUIndexSection = MCOFI.getDwarfCUIndexSection();
242244
const StringMap<std::pair<MCSection *, DWARFSectionKind>> KnownSections = {
243245
{"debug_info.dwo", {MCOFI.getDwarfInfoDWOSection(), DW_SECT_INFO}},
244246
{"debug_types.dwo", {MCOFI.getDwarfTypesDWOSection(), DW_SECT_TYPES}},
245247
{"debug_str_offsets.dwo", {StrOffsetSection, DW_SECT_STR_OFFSETS}},
246248
{"debug_str.dwo", {StrSection, static_cast<DWARFSectionKind>(0)}},
247249
{"debug_loc.dwo", {MCOFI.getDwarfLocDWOSection(), DW_SECT_LOC}},
248250
{"debug_line.dwo", {MCOFI.getDwarfLineDWOSection(), DW_SECT_LINE}},
249-
{"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}}};
251+
{"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}},
252+
{"debug_cu_index",
253+
{MCOFI.getDwarfCUIndexSection(), static_cast<DWARFSectionKind>(0)}}};
250254

251255
std::vector<UnitIndexEntry> IndexEntries;
252256
std::vector<UnitIndexEntry> TypeIndexEntries;
@@ -261,14 +265,14 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
261265
if (!ErrOrObj)
262266
return ErrOrObj.getError();
263267

264-
IndexEntries.emplace_back();
265-
UnitIndexEntry &CurEntry = IndexEntries.back();
268+
UnitIndexEntry CurEntry = {};
266269

267270
StringRef CurStrSection;
268271
StringRef CurStrOffsetSection;
269272
StringRef CurTypesSection;
270273
StringRef InfoSection;
271274
StringRef AbbrevSection;
275+
StringRef CurCUIndexSection;
272276

273277
for (const auto &Section : ErrOrObj->getBinary()->sections()) {
274278
StringRef Name;
@@ -311,6 +315,8 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
311315
CurStrSection = Contents;
312316
else if (OutSection == TypesSection)
313317
CurTypesSection = Contents;
318+
else if (OutSection == CUIndexSection)
319+
CurCUIndexSection = Contents;
314320
else {
315321
Out.SwitchSection(OutSection);
316322
Out.EmitBytes(Contents);
@@ -319,9 +325,34 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
319325

320326
assert(!AbbrevSection.empty());
321327
assert(!InfoSection.empty());
322-
CurEntry.Signature = getCUSignature(AbbrevSection, InfoSection);
323-
addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection, CurEntry,
324-
ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]);
328+
if (!CurCUIndexSection.empty()) {
329+
DWARFUnitIndex CUIndex(DW_SECT_INFO);
330+
DataExtractor CUIndexData(CurCUIndexSection,
331+
ErrOrObj->getBinary()->isLittleEndian(), 0);
332+
if (!CUIndex.parse(CUIndexData))
333+
return make_error_code(std::errc::invalid_argument);
334+
335+
for (const DWARFUnitIndex::Entry &E : CUIndex.getRows()) {
336+
auto NewEntry = CurEntry;
337+
auto *I = E.getOffsets();
338+
if (!I)
339+
continue;
340+
NewEntry.Signature = E.getSignature();
341+
for (auto Kind : CUIndex.getColumnKinds()) {
342+
auto &C = NewEntry.Contributions[Kind - DW_SECT_INFO];
343+
C.Offset += I->Offset;
344+
C.Length = I->Length;
345+
++I;
346+
}
347+
IndexEntries.push_back(NewEntry);
348+
}
349+
} else {
350+
CurEntry.Signature = getCUSignature(AbbrevSection, InfoSection);
351+
addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection,
352+
CurEntry, ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]);
353+
354+
IndexEntries.push_back(CurEntry);
355+
}
325356

326357
if (auto Err = writeStringsAndOffsets(Out, Strings, StringOffset,
327358
StrSection, StrOffsetSection,

0 commit comments

Comments
 (0)