@@ -505,7 +505,7 @@ static Error materializeDebugInfoOpt(MCCASReader &Reader,
505
505
StringRef FormData, bool ) {
506
506
if (Form == dwarf::Form::DW_FORM_ref4_cas ||
507
507
Form == dwarf::Form::DW_FORM_strp_cas) {
508
- DataExtractor Extractor (FormData, true , 8 );
508
+ DataExtractor Extractor (FormData, true , Reader. getAddressSize () );
509
509
DataExtractor::Cursor Cursor (0 );
510
510
uint64_t Data64 = Extractor.getULEB128 (Cursor);
511
511
if (!Cursor)
@@ -529,7 +529,7 @@ static Error materializeDebugInfoOpt(MCCASReader &Reader,
529
529
530
530
if (auto E = visitDebugInfo (TotAbbrevEntries, std::move (MaybeTopRef),
531
531
HeaderCallback, StartTagCallback, AttrCallback,
532
- EndTagCallback))
532
+ EndTagCallback, Reader. getAddressSize () ))
533
533
return E;
534
534
}
535
535
return Error::success ();
@@ -826,10 +826,11 @@ getLineTableLengthInfoAndVersion(DWARFDataExtractor &LineTableDataReader,
826
826
auto AddressSize = LineTableDataReader.getU8 (OffsetPtr, &Err);
827
827
if (Err)
828
828
return std::move (Err);
829
- if (AddressSize != 8 )
829
+ if (AddressSize != LineTableDataReader. getAddressSize () )
830
830
return createStringError (
831
831
inconvertibleErrorCode (),
832
- " Address size is not 8 bytes, unsupported architecture for MCCAS!" );
832
+ " Address size in line table header is not the same as Address size "
833
+ " for the target architecture, something went really wrong!" );
833
834
LineTableDataReader.getU8 (OffsetPtr, &Err);
834
835
if (Err)
835
836
return std::move (Err);
@@ -956,9 +957,12 @@ handleStandardOpcodesForLineTable(DWARFDataExtractor &LineTableDataReader,
956
957
static Expected<std::pair<uint64_t , uint64_t >>
957
958
getOpcodeAndOperandSize (StringRef DistinctData, StringRef LineTableData,
958
959
uint64_t DistinctOffset, uint64_t LineTableOffset,
959
- bool IsLittleEndian, uint8_t OpcodeBase) {
960
- DWARFDataExtractor LineTableDataReader (LineTableData, IsLittleEndian, 8 );
961
- DWARFDataExtractor DistinctDataReader (DistinctData, IsLittleEndian, 8 );
960
+ bool IsLittleEndian, uint8_t OpcodeBase,
961
+ uint8_t AddressSize) {
962
+ DWARFDataExtractor LineTableDataReader (LineTableData, IsLittleEndian,
963
+ AddressSize);
964
+ DWARFDataExtractor DistinctDataReader (DistinctData, IsLittleEndian,
965
+ AddressSize);
962
966
DWARFDataExtractor::Cursor LineTableCursor (LineTableOffset);
963
967
DWARFDataExtractor::Cursor DistinctCursor (DistinctOffset);
964
968
@@ -1064,7 +1068,8 @@ materializeDebugLineSection(MCCASReader &Reader,
1064
1068
DistinctDebugLineRefSeen = true ;
1065
1069
auto Data = DistinctRef->getData ();
1066
1070
DistinctData.append (Data.begin (), Data.end ());
1067
- DWARFDataExtractor LineTableDataReader (Data, Reader.getEndian (), 8 );
1071
+ DWARFDataExtractor LineTableDataReader (Data, Reader.getEndian (),
1072
+ Reader.getAddressSize ());
1068
1073
auto Prologue = parseLineTableHeaderAndSkip (LineTableDataReader);
1069
1074
if (!Prologue)
1070
1075
return Prologue.takeError ();
@@ -1084,9 +1089,9 @@ materializeDebugLineSection(MCCASReader &Reader,
1084
1089
auto Data = LineRef->getData ();
1085
1090
uint64_t LineTableOffset = 0 ;
1086
1091
while (LineTableOffset < Data.size ()) {
1087
- auto Sizes = getOpcodeAndOperandSize (toStringRef (DistinctData), Data,
1088
- DistinctOffset, LineTableOffset,
1089
- Reader.getEndian (), OpcodeBase);
1092
+ auto Sizes = getOpcodeAndOperandSize (
1093
+ toStringRef (DistinctData), Data, DistinctOffset, LineTableOffset,
1094
+ Reader.getEndian (), OpcodeBase, Reader. getAddressSize () );
1090
1095
if (!Sizes)
1091
1096
return Sizes.takeError ();
1092
1097
// Copy opcode and operand, only in the case of DW_LNS_set_file, the
@@ -1725,12 +1730,11 @@ static Expected<size_t> getSizeFromDwarfHeader(DataExtractor &Extractor,
1725
1730
// / contained in CUData, as well as the total number of bytes taken by the CU.
1726
1731
// / Note: this is different from the length field of the Dwarf header, which
1727
1732
// / does not account for the header size.
1728
- static Expected<CUInfo>
1729
- getAndSetDebugAbbrevOffsetAndSkip (MutableArrayRef<char > CUData,
1730
- support::endianness Endian,
1731
- std::optional<uint32_t > NewOffset) {
1733
+ static Expected<CUInfo> getAndSetDebugAbbrevOffsetAndSkip (
1734
+ MutableArrayRef<char > CUData, support::endianness Endian,
1735
+ std::optional<uint32_t > NewOffset, uint8_t AddressSize) {
1732
1736
DataExtractor Extractor (toStringRef (CUData),
1733
- Endian == support::endianness::little, 8 );
1737
+ Endian == support::endianness::little, AddressSize );
1734
1738
DataExtractor::Cursor Cursor (0 );
1735
1739
Expected<size_t > Size = getSizeFromDwarfHeader (Extractor, Cursor);
1736
1740
if (!Size)
@@ -1754,13 +1758,14 @@ getAndSetDebugAbbrevOffsetAndSkip(MutableArrayRef<char> CUData,
1754
1758
return createStringError (
1755
1759
inconvertibleErrorCode (),
1756
1760
" Unit type is not DW_UT_compile, and is incompatible with MCCAS!" );
1757
- uint8_t AddressSize = Extractor.getU8 (Cursor);
1761
+ uint8_t HeaderAddressSize = Extractor.getU8 (Cursor);
1758
1762
if (!Cursor)
1759
1763
return Cursor.takeError ();
1760
- if (AddressSize != 8 )
1764
+ if (HeaderAddressSize != AddressSize )
1761
1765
return createStringError (
1762
1766
inconvertibleErrorCode (),
1763
- " Address size is not 8 bytes, unsupported architecture for MCCAS!" );
1767
+ " Address size in Compile Unit header is not the same as Address size "
1768
+ " for the target architecture, something went really wrong!" );
1764
1769
}
1765
1770
1766
1771
// TODO: Handle Dwarf 64 format, which uses 8 bytes.
@@ -1815,7 +1820,8 @@ MCCASBuilder::splitDebugInfoSectionData(MutableArrayRef<char> DebugInfoData) {
1815
1820
// CU splitting loop.
1816
1821
while (!DebugInfoData.empty ()) {
1817
1822
Expected<CUInfo> Info = getAndSetDebugAbbrevOffsetAndSkip (
1818
- DebugInfoData, Asm.getBackend ().Endian , /* NewOffset*/ 0 );
1823
+ DebugInfoData, Asm.getBackend ().Endian , /* NewOffset*/ 0 ,
1824
+ ObjectWriter.getAddressSize ());
1819
1825
if (!Info)
1820
1826
return Info.takeError ();
1821
1827
Split.SplitCUData .push_back (DebugInfoData.take_front (Info->CUSize ));
@@ -1981,12 +1987,15 @@ Error InMemoryCASDWARFObject::partitionCUData(ArrayRef<char> DebugInfoData,
1981
1987
uint16_t DwarfVersion) {
1982
1988
StringRef AbbrevSectionContribution =
1983
1989
getAbbrevSection ().drop_front (AbbrevOffset);
1984
- DataExtractor Data (AbbrevSectionContribution, isLittleEndian (), 8 );
1990
+ DataExtractor Data (AbbrevSectionContribution, isLittleEndian (),
1991
+ Builder.ObjectWriter .getAddressSize ());
1985
1992
DWARFDebugAbbrev Abbrev (Data);
1986
1993
uint64_t OffsetPtr = 0 ;
1987
1994
DWARFUnitHeader Header;
1988
1995
DWARFSection Section = {toStringRef (DebugInfoData), 0 /* Address*/ };
1989
- Header.extract (*Ctx, DWARFDataExtractor (*this , Section, isLittleEndian (), 8 ),
1996
+ Header.extract (*Ctx,
1997
+ DWARFDataExtractor (*this , Section, isLittleEndian (),
1998
+ Builder.ObjectWriter .getAddressSize ()),
1990
1999
&OffsetPtr, DWARFSectionKind::DW_SECT_INFO);
1991
2000
1992
2001
DWARFUnitVector UV;
@@ -2084,8 +2093,8 @@ inline void copyData(SmallVector<char, 0> &Data, StringRef DebugLineStrRef,
2084
2093
2085
2094
Expected<uint64_t >
2086
2095
MCCASBuilder::createOptimizedLineSection (StringRef DebugLineStrRef) {
2087
- DWARFDataExtractor LineTableDataReader (DebugLineStrRef,
2088
- Asm.getBackend ().Endian , 8 );
2096
+ DWARFDataExtractor LineTableDataReader (
2097
+ DebugLineStrRef, Asm.getBackend ().Endian , ObjectWriter. getAddressSize () );
2089
2098
auto Prologue = parseLineTableHeaderAndSkip (LineTableDataReader);
2090
2099
if (!Prologue)
2091
2100
return Prologue.takeError ();
@@ -3127,20 +3136,19 @@ Error DIEVisitor::visitDIEAttrs(DataExtractor &Extractor,
3127
3136
StringRef DIEData,
3128
3137
ArrayRef<AbbrevContent> DIEContents) {
3129
3138
constexpr auto IsLittleEndian = true ;
3130
- constexpr auto AddrSize = 8 ;
3131
- auto FormParams =
3132
- dwarf::FormParams{DwarfVersion, AddrSize, dwarf::DwarfFormat::DWARF32};
3139
+ auto FormParams = dwarf::FormParams{DwarfVersion, Extractor.getAddressSize (),
3140
+ dwarf::DwarfFormat::DWARF32};
3133
3141
3134
3142
for (auto Contents : DIEContents) {
3135
3143
bool DataInDistinct = Contents.FormInDistinctData ;
3136
3144
auto &ExtractorForData = DataInDistinct ? DistinctExtractor : Extractor;
3137
3145
auto &CursorForData = DataInDistinct ? DistinctCursor : Cursor;
3138
3146
StringRef DataToUse = DataInDistinct ? DistinctData : DIEData;
3139
3147
Expected<uint64_t > FormSize =
3140
- Contents.FormSize
3141
- ? * Contents.FormSize
3142
- : getFormSize (Contents. Form , FormParams, DataToUse ,
3143
- CursorForData. tell (), IsLittleEndian, AddrSize );
3148
+ Contents.FormSize ? *Contents. FormSize
3149
+ : getFormSize ( Contents.Form , FormParams, DataToUse,
3150
+ CursorForData. tell (), IsLittleEndian ,
3151
+ Extractor. getAddressSize () );
3144
3152
if (!FormSize)
3145
3153
return FormSize.takeError ();
3146
3154
@@ -3241,9 +3249,9 @@ static std::optional<uint8_t> getNonULEBFormSize(dwarf::Form Form,
3241
3249
}
3242
3250
3243
3251
Error DIEVisitor::materializeAbbrevDIE (unsigned AbbrevIdx) {
3244
- constexpr auto AddrSize = 8 ;
3245
3252
auto FormParams =
3246
- dwarf::FormParams{DwarfVersion, AddrSize, dwarf::DwarfFormat::DWARF32};
3253
+ dwarf::FormParams{DwarfVersion, DistinctExtractor.getAddressSize (),
3254
+ dwarf::DwarfFormat::DWARF32};
3247
3255
3248
3256
AbbrevEntryReader AbbrevReader =
3249
3257
getAbbrevEntryReader (AbbrevEntries, AbbrevIdx);
@@ -3281,9 +3289,10 @@ Error DIEVisitor::materializeAbbrevDIE(unsigned AbbrevIdx) {
3281
3289
// / previous stack frame.
3282
3290
static void popStack (DataExtractor &Extractor, DataExtractor::Cursor &Cursor,
3283
3291
StringRef &Data,
3284
- std::stack<std::pair<StringRef, unsigned >> &StackOfNodes) {
3292
+ std::stack<std::pair<StringRef, unsigned >> &StackOfNodes,
3293
+ uint8_t AddressSize) {
3285
3294
auto DataAndOffset = StackOfNodes.top ();
3286
- Extractor = DataExtractor (DataAndOffset.first , true , 8 );
3295
+ Extractor = DataExtractor (DataAndOffset.first , true , AddressSize );
3287
3296
Data = DataAndOffset.first ;
3288
3297
Cursor.seek (DataAndOffset.second );
3289
3298
StackOfNodes.pop ();
@@ -3299,7 +3308,7 @@ Error DIEVisitor::visitDIERef(ArrayRef<DIEDataRef> &DIEChildrenStack) {
3299
3308
std::stack<std::pair<StringRef, unsigned >> StackOfNodes;
3300
3309
auto Data = DIEChildrenStack.empty () ? StringRef ()
3301
3310
: DIEChildrenStack.front ().getData ();
3302
- DataExtractor Extractor (Data, true , 8 );
3311
+ DataExtractor Extractor (Data, true , DistinctExtractor. getAddressSize () );
3303
3312
DataExtractor::Cursor Cursor (0 );
3304
3313
3305
3314
while (!DistinctExtractor.eof (DistinctCursor)) {
@@ -3316,7 +3325,8 @@ Error DIEVisitor::visitDIERef(ArrayRef<DIEDataRef> &DIEChildrenStack) {
3316
3325
if (AbbrevIdx == getEndOfDIESiblingsMarker ()) {
3317
3326
EndTagCallback (true /* HadChildren*/ );
3318
3327
if (!StackOfNodes.empty () && Extractor.eof (Cursor))
3319
- popStack (Extractor, Cursor, Data, StackOfNodes);
3328
+ popStack (Extractor, Cursor, Data, StackOfNodes,
3329
+ DistinctExtractor.getAddressSize ());
3320
3330
continue ;
3321
3331
}
3322
3332
@@ -3328,7 +3338,7 @@ Error DIEVisitor::visitDIERef(ArrayRef<DIEDataRef> &DIEChildrenStack) {
3328
3338
DIEChildrenStack = DIEChildrenStack.drop_front ();
3329
3339
Data = DIEChildrenStack.front ().getData ();
3330
3340
NewBlockCallback (DIEChildrenStack.front ().getID ().toString ());
3331
- Extractor = DataExtractor (Data, true , 8 );
3341
+ Extractor = DataExtractor (Data, true , DistinctExtractor. getAddressSize () );
3332
3342
Cursor.seek (0 );
3333
3343
continue ;
3334
3344
}
@@ -3347,7 +3357,8 @@ Error DIEVisitor::visitDIERef(ArrayRef<DIEDataRef> &DIEChildrenStack) {
3347
3357
// parent's siblings that may exist.
3348
3358
if (!AbbrevEntryCacheVal.HasChildren ) {
3349
3359
if (!StackOfNodes.empty () && Extractor.eof (Cursor))
3350
- popStack (Extractor, Cursor, Data, StackOfNodes);
3360
+ popStack (Extractor, Cursor, Data, StackOfNodes,
3361
+ DistinctExtractor.getAddressSize ());
3351
3362
EndTagCallback (false /* HadChildren*/ );
3352
3363
}
3353
3364
}
@@ -3387,7 +3398,7 @@ Error mccasformats::v1::visitDebugInfo(
3387
3398
std::function<void(dwarf::Tag, uint64_t )> StartTagCallback,
3388
3399
std::function<void(dwarf::Attribute, dwarf::Form, StringRef, bool )>
3389
3400
AttrCallback,
3390
- std::function<void(bool )> EndTagCallback,
3401
+ std::function<void(bool )> EndTagCallback, uint8_t AddressSize,
3391
3402
std::function<void(StringRef)> NewBlockCallback) {
3392
3403
3393
3404
Expected<LoadedDIETopLevel> LoadedTopRef =
@@ -3406,7 +3417,7 @@ Error mccasformats::v1::visitDebugInfo(
3406
3417
return E;
3407
3418
DistinctData = toStringRef (OutBuff);
3408
3419
#endif
3409
- DataExtractor DistinctExtractor (DistinctData, true , 8 );
3420
+ DataExtractor DistinctExtractor (DistinctData, true , AddressSize );
3410
3421
DataExtractor::Cursor DistinctCursor (0 );
3411
3422
3412
3423
auto Size = getSizeFromDwarfHeader (DistinctExtractor, DistinctCursor);
0 commit comments