@@ -1375,9 +1375,46 @@ static Expected<uint64_t> materializeGenericDebugSection(MCCASReader &Reader,
1375
1375
Expected<uint64_t >
1376
1376
DebugStringOffsetsSectionRef::materialize (MCCASReader &Reader,
1377
1377
raw_ostream *Stream) const {
1378
+ // Start a new section for relocations.
1379
+ Reader.Relocations .emplace_back ();
1380
+ SmallVector<char , 0 > SectionContents;
1381
+ raw_svector_ostream SectionStream (SectionContents);
1382
+
1383
+ unsigned Size = 0 ;
1378
1384
StringRef Remaining = getData ();
1379
- return materializeGenericDebugSection<DebugStringOffsetsSectionRef>(
1380
- Reader, Remaining, *this );
1385
+ auto Refs = DebugStringOffsetsSectionRef::decodeReferences (*this , Remaining);
1386
+ if (!Refs)
1387
+ return Refs.takeError ();
1388
+
1389
+ for (auto ID : *Refs) {
1390
+ auto FragmentSize = Reader.materializeSection (ID, &SectionStream);
1391
+ if (!FragmentSize)
1392
+ return FragmentSize.takeError ();
1393
+ Size += *FragmentSize;
1394
+ }
1395
+
1396
+ if (auto E = decodeRelocations (Reader, Remaining))
1397
+ return std::move (E);
1398
+
1399
+ #if LLVM_ENABLE_ZLIB
1400
+ StringRef SectionStringRef = toStringRef (SectionContents);
1401
+ ArrayRef<uint8_t > BufRef = arrayRefFromStringRef (SectionStringRef);
1402
+ assert (BufRef.size () >= 8 &&
1403
+ " Debug String Offset buffer less than 8 bytes in size!" );
1404
+ // The zlib decompress function needs to know the uncompressed size of the
1405
+ // buffer. That size is stored as a ULEB at the end of the buffer
1406
+ auto UncompressedSize = decodeULEB128 (BufRef.data () + BufRef.size () - 8 );
1407
+ BufRef = BufRef.drop_back (8 );
1408
+ SmallVector<uint8_t > OutBuff;
1409
+ if (auto E = compression::zlib::decompress (BufRef, OutBuff, UncompressedSize))
1410
+ return E;
1411
+ SectionStringRef = toStringRef (OutBuff);
1412
+ Reader.OS << SectionStringRef;
1413
+ return UncompressedSize;
1414
+ #endif
1415
+
1416
+ Reader.OS << SectionContents;
1417
+ return Size;
1381
1418
}
1382
1419
1383
1420
Expected<uint64_t > DebugLocSectionRef::materialize (MCCASReader &Reader,
@@ -2625,10 +2662,44 @@ MCCASBuilder::createGenericDebugRef(MCSection *Section) {
2625
2662
return *DebugCASRef;
2626
2663
}
2627
2664
2665
+ std::optional<Expected<DebugStrOffsetsRef>>
2666
+ MCCASBuilder::createDebugStrOffsetsRef () {
2667
+
2668
+ if (!DwarfSections.StrOffsets ||
2669
+ !DwarfSections.StrOffsets ->getFragmentList ().size ())
2670
+ return std::nullopt;
2671
+
2672
+ auto DebugStrOffsetsData = mergeMCFragmentContents (
2673
+ DwarfSections.StrOffsets ->getFragmentList (), false );
2674
+
2675
+ if (!DebugStrOffsetsData)
2676
+ return DebugStrOffsetsData.takeError ();
2677
+
2678
+ #if LLVM_ENABLE_ZLIB
2679
+ SmallVector<uint8_t > CompressedBuff;
2680
+ compression::zlib::compress (
2681
+ arrayRefFromStringRef (toStringRef (*DebugStrOffsetsData)), CompressedBuff);
2682
+ // Reserve 8 bytes for ULEB to store the size of the uncompressed data.
2683
+ CompressedBuff.append (8 , 0 );
2684
+ encodeULEB128 (DebugStrOffsetsData->size (), CompressedBuff.end () - 8 ,
2685
+ 8 /* Pad to*/ );
2686
+ auto DbgStrOffsetsRef =
2687
+ DebugStrOffsetsRef::create (*this , toStringRef (CompressedBuff));
2688
+ if (!DbgStrOffsetsRef)
2689
+ return DbgStrOffsetsRef.takeError ();
2690
+ return *DbgStrOffsetsRef;
2691
+ #else
2692
+ auto DbgStrOffsetsRef =
2693
+ DebugStrOffsetsRef::create (*this , toStringRef (CompressedBuff));
2694
+ if (!DbgStrOffsetsRef)
2695
+ return DbgStrOffsetsRef.takeError ();
2696
+ return *DbgStrOffsetsRef;
2697
+ #endif
2698
+ }
2699
+
2628
2700
Error MCCASBuilder::createDebugStrOffsetsSection () {
2629
2701
2630
- auto MaybeDebugStringOffsetsRef =
2631
- createGenericDebugRef<DebugStrOffsetsRef>(DwarfSections.StrOffsets );
2702
+ auto MaybeDebugStringOffsetsRef = createDebugStrOffsetsRef ();
2632
2703
if (!MaybeDebugStringOffsetsRef)
2633
2704
return Error::success ();
2634
2705
0 commit comments