@@ -142,27 +142,15 @@ readBinaryIdsInternal(const MemoryBuffer &DataBuffer,
142
142
return Error::success ();
143
143
}
144
144
145
- static Error printBinaryIdsInternal (raw_ostream &OS,
146
- const MemoryBuffer &DataBuffer,
147
- uint64_t BinaryIdsSize,
148
- const uint8_t *BinaryIdsStart,
149
- llvm::endianness Endian) {
150
- if (BinaryIdsSize == 0 )
151
- return Error::success ();
152
-
153
- std::vector<llvm::object::BuildID> BinaryIds;
154
- if (Error E = readBinaryIdsInternal (DataBuffer, BinaryIdsSize, BinaryIdsStart,
155
- BinaryIds, Endian))
156
- return E;
157
-
145
+ static void
146
+ printBinaryIdsInternal (raw_ostream &OS,
147
+ std::vector<llvm::object::BuildID> &BinaryIds) {
158
148
OS << " Binary IDs: \n " ;
159
149
for (auto BI : BinaryIds) {
160
150
for (uint64_t I = 0 ; I < BI.size (); I++)
161
151
OS << format (" %02x" , BI[I]);
162
152
OS << " \n " ;
163
153
}
164
-
165
- return Error::success ();
166
154
}
167
155
168
156
Expected<std::unique_ptr<InstrProfReader>>
@@ -573,9 +561,20 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
573
561
if (!useCorrelate () && Correlator)
574
562
return error (instrprof_error::unexpected_debug_info_for_correlation);
575
563
576
- BinaryIdsSize = swap (Header.BinaryIdsSize );
577
- if (BinaryIdsSize % sizeof (uint64_t ))
564
+ uint64_t BinaryIdSize = swap (Header.BinaryIdsSize );
565
+ // Binary id start just after the header if exists.
566
+ const uint8_t *BinaryIdStart =
567
+ reinterpret_cast <const uint8_t *>(&Header) + sizeof (RawInstrProf::Header);
568
+ const uint8_t *BinaryIdEnd = BinaryIdStart + BinaryIdSize;
569
+ const uint8_t *BufferEnd = (const uint8_t *)DataBuffer->getBufferEnd ();
570
+ if (BinaryIdSize % sizeof (uint64_t ) || BinaryIdEnd > BufferEnd)
578
571
return error (instrprof_error::bad_header);
572
+ if (BinaryIdSize != 0 ) {
573
+ if (Error Err =
574
+ readBinaryIdsInternal (*DataBuffer, BinaryIdSize, BinaryIdStart,
575
+ BinaryIds, getDataEndianness ()))
576
+ return Err;
577
+ }
579
578
580
579
CountersDelta = swap (Header.CountersDelta );
581
580
BitmapDelta = swap (Header.BitmapDelta );
@@ -593,7 +592,7 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
593
592
auto PaddingSize = getNumPaddingBytes (NamesSize);
594
593
595
594
// Profile data starts after profile header and binary ids if exist.
596
- ptrdiff_t DataOffset = sizeof (RawInstrProf::Header) + BinaryIdsSize ;
595
+ ptrdiff_t DataOffset = sizeof (RawInstrProf::Header) + BinaryIdSize ;
597
596
ptrdiff_t CountersOffset = DataOffset + DataSize + PaddingBytesBeforeCounters;
598
597
ptrdiff_t BitmapOffset =
599
598
CountersOffset + CountersSize + PaddingBytesAfterCounters;
@@ -622,19 +621,12 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
622
621
NamesEnd = NamesStart + NamesSize;
623
622
}
624
623
625
- // Binary ids start just after the header.
626
- BinaryIdsStart =
627
- reinterpret_cast <const uint8_t *>(&Header) + sizeof (RawInstrProf::Header);
628
624
CountersStart = Start + CountersOffset;
629
625
CountersEnd = CountersStart + CountersSize;
630
626
BitmapStart = Start + BitmapOffset;
631
627
BitmapEnd = BitmapStart + NumBitmapBytes;
632
628
ValueDataStart = reinterpret_cast <const uint8_t *>(Start + ValueDataOffset);
633
629
634
- const uint8_t *BufferEnd = (const uint8_t *)DataBuffer->getBufferEnd ();
635
- if (BinaryIdsStart + BinaryIdsSize > BufferEnd)
636
- return error (instrprof_error::bad_header);
637
-
638
630
std::unique_ptr<InstrProfSymtab> NewSymtab = std::make_unique<InstrProfSymtab>();
639
631
if (Error E = createSymtab (*NewSymtab))
640
632
return E;
@@ -832,14 +824,16 @@ Error RawInstrProfReader<IntPtrT>::readNextRecord(NamedInstrProfRecord &Record)
832
824
template <class IntPtrT >
833
825
Error RawInstrProfReader<IntPtrT>::readBinaryIds(
834
826
std::vector<llvm::object::BuildID> &BinaryIds) {
835
- return readBinaryIdsInternal (*DataBuffer, BinaryIdsSize, BinaryIdsStart,
836
- BinaryIds, getDataEndianness ());
827
+ BinaryIds.insert (BinaryIds.begin (), this ->BinaryIds .begin (),
828
+ this ->BinaryIds .end ());
829
+ return Error::success ();
837
830
}
838
831
839
832
template <class IntPtrT >
840
833
Error RawInstrProfReader<IntPtrT>::printBinaryIds(raw_ostream &OS) {
841
- return printBinaryIdsInternal (OS, *DataBuffer, BinaryIdsSize, BinaryIdsStart,
842
- getDataEndianness ());
834
+ if (!BinaryIds.empty ())
835
+ printBinaryIdsInternal (OS, BinaryIds);
836
+ return Error::success ();
843
837
}
844
838
845
839
namespace llvm {
@@ -1475,8 +1469,11 @@ Error IndexedInstrProfReader::readBinaryIds(
1475
1469
}
1476
1470
1477
1471
Error IndexedInstrProfReader::printBinaryIds (raw_ostream &OS) {
1478
- return printBinaryIdsInternal (OS, *DataBuffer, BinaryIdsSize, BinaryIdsStart,
1479
- llvm::endianness::little);
1472
+ std::vector<llvm::object::BuildID> BinaryIds;
1473
+ if (Error E = readBinaryIds (BinaryIds))
1474
+ return E;
1475
+ printBinaryIdsInternal (OS, BinaryIds);
1476
+ return Error::success ();
1480
1477
}
1481
1478
1482
1479
void InstrProfReader::accumulateCounts (CountSumOrPercent &Sum, bool IsCS) {
0 commit comments