24
24
#include < list>
25
25
#include < memory>
26
26
#include < unordered_set>
27
+ #include < system_error>
27
28
28
29
using namespace llvm ;
29
30
using namespace llvm ::object;
@@ -239,14 +240,17 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
239
240
MCSection *const StrSection = MCOFI.getDwarfStrDWOSection ();
240
241
MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection ();
241
242
MCSection *const TypesSection = MCOFI.getDwarfTypesDWOSection ();
243
+ MCSection *const CUIndexSection = MCOFI.getDwarfCUIndexSection ();
242
244
const StringMap<std::pair<MCSection *, DWARFSectionKind>> KnownSections = {
243
245
{" debug_info.dwo" , {MCOFI.getDwarfInfoDWOSection (), DW_SECT_INFO}},
244
246
{" debug_types.dwo" , {MCOFI.getDwarfTypesDWOSection (), DW_SECT_TYPES}},
245
247
{" debug_str_offsets.dwo" , {StrOffsetSection, DW_SECT_STR_OFFSETS}},
246
248
{" debug_str.dwo" , {StrSection, static_cast <DWARFSectionKind>(0 )}},
247
249
{" debug_loc.dwo" , {MCOFI.getDwarfLocDWOSection (), DW_SECT_LOC}},
248
250
{" 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 )}}};
250
254
251
255
std::vector<UnitIndexEntry> IndexEntries;
252
256
std::vector<UnitIndexEntry> TypeIndexEntries;
@@ -261,14 +265,14 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
261
265
if (!ErrOrObj)
262
266
return ErrOrObj.getError ();
263
267
264
- IndexEntries.emplace_back ();
265
- UnitIndexEntry &CurEntry = IndexEntries.back ();
268
+ UnitIndexEntry CurEntry = {};
266
269
267
270
StringRef CurStrSection;
268
271
StringRef CurStrOffsetSection;
269
272
StringRef CurTypesSection;
270
273
StringRef InfoSection;
271
274
StringRef AbbrevSection;
275
+ StringRef CurCUIndexSection;
272
276
273
277
for (const auto &Section : ErrOrObj->getBinary ()->sections ()) {
274
278
StringRef Name;
@@ -311,6 +315,8 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
311
315
CurStrSection = Contents;
312
316
else if (OutSection == TypesSection)
313
317
CurTypesSection = Contents;
318
+ else if (OutSection == CUIndexSection)
319
+ CurCUIndexSection = Contents;
314
320
else {
315
321
Out.SwitchSection (OutSection);
316
322
Out.EmitBytes (Contents);
@@ -319,9 +325,34 @@ static std::error_code write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
319
325
320
326
assert (!AbbrevSection.empty ());
321
327
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
+ }
325
356
326
357
if (auto Err = writeStringsAndOffsets (Out, Strings, StringOffset,
327
358
StrSection, StrOffsetSection,
0 commit comments