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