Skip to content

Commit 7d7e44e

Browse files
committed
Fix merging of debug_str_offsets with multiple contributions in the section
added test of merging contributions in debug_str_offsets
1 parent 99de3a6 commit 7d7e44e

File tree

5 files changed

+86
-9
lines changed

5 files changed

+86
-9
lines changed

llvm/lib/DWP/DWP.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,17 @@ Expected<InfoSectionUnitHeader> parseInfoSectionUnitHeader(StringRef Info) {
415415
return Header;
416416
}
417417

418+
static void writeNewOffsetsTo(MCStreamer &Out, DataExtractor &Data,
419+
DenseMap<uint64_t, uint32_t> &OffsetRemapping,
420+
uint64_t &Offset, uint64_t &Size) {
421+
422+
while (Offset < Size) {
423+
auto OldOffset = Data.getU32(&Offset);
424+
auto NewOffset = OffsetRemapping[OldOffset];
425+
Out.emitIntValue(NewOffset, 4);
426+
}
427+
}
428+
418429
void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
419430
MCSection *StrOffsetSection,
420431
StringRef CurStrSection,
@@ -439,17 +450,30 @@ void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
439450

440451
Out.switchSection(StrOffsetSection);
441452

442-
uint64_t HeaderSize = debugStrOffsetsHeaderSize(Data, Version);
443453
uint64_t Offset = 0;
444454
uint64_t Size = CurStrOffsetSection.size();
445-
// FIXME: This can be caused by bad input and should be handled as such.
446-
assert(HeaderSize <= Size && "StrOffsetSection size is less than its header");
447-
// Copy the header to the output.
448-
Out.emitBytes(Data.getBytes(&Offset, HeaderSize));
449-
while (Offset < Size) {
450-
auto OldOffset = Data.getU32(&Offset);
451-
auto NewOffset = OffsetRemapping[OldOffset];
452-
Out.emitIntValue(NewOffset, 4);
455+
if (Version > 4) {
456+
while (Offset < Size) {
457+
uint64_t HeaderSize = debugStrOffsetsHeaderSize(Data, Version);
458+
assert(HeaderSize <= Size - Offset &&
459+
"StrOffsetSection size is less than its header");
460+
461+
uint64_t ContributionEnd = 0;
462+
uint64_t ContributionSize = 0;
463+
uint64_t HeaderLengthOffset = Offset;
464+
if (HeaderSize == 8) {
465+
ContributionSize = Data.getU32(&HeaderLengthOffset);
466+
} else if (HeaderSize == 16) {
467+
HeaderLengthOffset += 4; // skip the dwarf64 marker
468+
ContributionSize = Data.getU64(&HeaderLengthOffset);
469+
}
470+
ContributionEnd = ContributionSize + HeaderLengthOffset;
471+
Out.emitBytes(Data.getBytes(&Offset, HeaderSize));
472+
writeNewOffsetsTo(Out, Data, OffsetRemapping, Offset, ContributionEnd);
473+
}
474+
475+
} else {
476+
writeNewOffsetsTo(Out, Data, OffsetRemapping, Offset, Size);
453477
}
454478
}
455479

Binary file not shown.
Binary file not shown.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ CHECK: Index Signature INFO ABBREV
4444
CHECK-DAG: [[DWOC]] [0x00000000[[#COFF]], 0x00000000[[#AOFF]]) [0x0000[[CAOFF]], 0x0000[[AAOFF]]) [0x00000000, 0x00000011) [0x00000000, 0x00000018)
4545
CHECK-DAG: [[DWOA]] [0x00000000[[#AOFF]], 0x00000000[[#BOFF]]) [0x0000[[AAOFF]], 0x0000[[BAOFF]]) [0x00000011, 0x00000022) [0x00000018, 0x00000028)
4646
CHECK-DAG: [[DWOB]] [0x00000000[[#BOFF]], 0x00000000[[#XOFF]]) [0x0000[[BAOFF]], 0x000000c3) [0x00000022, 0x00000033) [0x00000028, 0x0000003c)
47+
48+
CHECK-LABEL: .debug_str_offsets.dwo contents:
49+
CHECK: Contribution size = 24, Format = DWARF32, Version = 4
50+
CHECK: Contribution size = 16, Format = DWARF32, Version = 4
51+
CHECK: Contribution size = 20, Format = DWARF32, Version = 4
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_v5/notypes/c.dwo %p/../Inputs/merge_v5/notypes/ab.dwp -o - | \
2+
RUN: llvm-dwarfdump -v - | FileCheck --check-prefix=CHECK %s
3+
4+
DWP from a DWO (c.dwo) and a DWP (ab.dwp, created from a.dwo and b.dwo)
5+
Make sure the entries for A and B are updated correctly when read/processed from ab.dwp
6+
a.cpp:
7+
struct foo { };
8+
foo a;
9+
10+
b.cpp:
11+
struct bar { };
12+
void b(bar) {
13+
}
14+
15+
c.cpp:
16+
typedef int baz;
17+
baz c() {
18+
}
19+
20+
CHECK-LABEL: .debug_abbrev.dwo contents:
21+
CHECK-LABEL: Abbrev table for offset:
22+
CHECK: 0x0000[[CAOFF:.*]]
23+
CHECK-LABEL: Abbrev table for offset:
24+
CHECK: 0x0000[[AAOFF:.*]]
25+
CHECK-LABEL: Abbrev table for offset:
26+
CHECK: 0x0000[[BAOFF:.*]]
27+
28+
CHECK: .debug_info.dwo contents:
29+
CHECK: 0x[[#%.8x,COFF:]]:
30+
CHECK-LABEL: Compile Unit: length = {{.*}}, format = DWARF32, version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset =
31+
CHECK: 0x[[CAOFF]], addr_size = 0x08, DWO_id = 0x[[DWOC:.*]] (next unit at 0x[[#%.8x,BOFF:]])
32+
CHECK: [[#BOFF]]:
33+
CHECK-LABEL: Compile Unit: length = {{.*}}, format = DWARF32, version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset =
34+
CHECK: 0x[[BAOFF]], addr_size = 0x08, DWO_id = 0x[[DWOB:.*]] (next unit at 0x[[#%.8x,AOFF:]])
35+
CHECK: [[#AOFF]]:
36+
CHECK-LABEL: Compile Unit: length = {{.*}}, format = DWARF32, version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset =
37+
CHECK: 0x[[AAOFF]], addr_size = 0x08, DWO_id = 0x[[DWOA:.*]] (next unit at 0x[[#%.8x,XOFF:]])
38+
39+
CHECK-LABEL: .debug_cu_index contents:
40+
CHECK: Index Signature INFO ABBREV STR_OFFSETS
41+
CHECK-DAG: [[DWOC]] [0x00000000[[#COFF]], 0x00000000[[#BOFF]]) [0x0000[[CAOFF]], 0x0000[[AAOFF]]) [0x00000000, 0x00000024)
42+
CHECK-DAG: [[DWOB]] [0x00000000[[#BOFF]], 0x00000000[[#AOFF]]) [0x0000[[BAOFF]],
43+
CHECK-DAG: [[DWOA]] [0x00000000[[#AOFF]], 0x00000000[[#XOFF]]) [0x0000[[AAOFF]],
44+
45+
CHECK-LABEL: .debug_str_offsets.dwo contents:
46+
CHECK: Contribution size = 32, Format = DWARF32, Version = 5
47+
CHECK: Contribution size = 24, Format = DWARF32, Version = 5
48+
CHECK: Contribution size = 28, Format = DWARF32, Version = 5

0 commit comments

Comments
 (0)