mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[llvm-cov] Support for v4 format in convert-for-testing
v4 moves function records to a dedicated section so we need to write and read it separately. https://reviews.llvm.org/D100535
This commit is contained in:
parent
40043ea4ca
commit
71ea50f517
@ -875,16 +875,43 @@ loadTestingFormat(StringRef Data) {
|
||||
InstrProfSymtab ProfileNames;
|
||||
if (Error E = ProfileNames.create(Data.substr(0, ProfileNamesSize), Address))
|
||||
return std::move(E);
|
||||
StringRef CoverageMapping = Data.substr(ProfileNamesSize);
|
||||
Data = Data.substr(ProfileNamesSize);
|
||||
// Skip the padding bytes because coverage map data has an alignment of 8.
|
||||
if (CoverageMapping.empty())
|
||||
return make_error<CoverageMapError>(coveragemap_error::truncated);
|
||||
size_t Pad = offsetToAlignedAddr(CoverageMapping.data(), Align(8));
|
||||
if (CoverageMapping.size() < Pad)
|
||||
size_t Pad = offsetToAlignedAddr(Data.data(), Align(8));
|
||||
if (Data.size() < Pad)
|
||||
return make_error<CoverageMapError>(coveragemap_error::malformed);
|
||||
CoverageMapping = CoverageMapping.substr(Pad);
|
||||
Data = Data.substr(Pad);
|
||||
if (Data.size() < sizeof(CovMapHeader))
|
||||
return make_error<CoverageMapError>(coveragemap_error::malformed);
|
||||
auto const *CovHeader = reinterpret_cast<const CovMapHeader *>(
|
||||
Data.substr(0, sizeof(CovMapHeader)).data());
|
||||
CovMapVersion Version =
|
||||
(CovMapVersion)CovHeader->getVersion<support::endianness::little>();
|
||||
StringRef CoverageMapping, CoverageRecords;
|
||||
if (Version < CovMapVersion::Version4) {
|
||||
CoverageMapping = Data;
|
||||
if (CoverageMapping.empty())
|
||||
return make_error<CoverageMapError>(coveragemap_error::truncated);
|
||||
} else {
|
||||
uint32_t FilenamesSize =
|
||||
CovHeader->getFilenamesSize<support::endianness::little>();
|
||||
uint32_t CoverageMappingSize = sizeof(CovMapHeader) + FilenamesSize;
|
||||
CoverageMapping = Data.substr(0, CoverageMappingSize);
|
||||
if (CoverageMapping.empty())
|
||||
return make_error<CoverageMapError>(coveragemap_error::truncated);
|
||||
Data = Data.substr(CoverageMappingSize);
|
||||
// Skip the padding bytes because coverage records data has an alignment
|
||||
// of 8.
|
||||
Pad = offsetToAlignedAddr(Data.data(), Align(8));
|
||||
if (Data.size() < Pad)
|
||||
return make_error<CoverageMapError>(coveragemap_error::malformed);
|
||||
CoverageRecords = Data.substr(Pad);
|
||||
if (CoverageRecords.empty())
|
||||
return make_error<CoverageMapError>(coveragemap_error::truncated);
|
||||
}
|
||||
return BinaryCoverageReader::createCoverageReaderFromBuffer(
|
||||
CoverageMapping, "", std::move(ProfileNames), BytesInAddress, Endian);
|
||||
CoverageMapping, CoverageRecords.str(), std::move(ProfileNames),
|
||||
BytesInAddress, Endian);
|
||||
}
|
||||
|
||||
/// Find all sections that match \p Name. There may be more than one if comdats
|
||||
|
@ -48,7 +48,7 @@ int convertForTestingMain(int argc, const char *argv[]) {
|
||||
|
||||
// Look for the sections that we are interested in.
|
||||
int FoundSectionCount = 0;
|
||||
SectionRef ProfileNames, CoverageMapping;
|
||||
SectionRef ProfileNames, CoverageMapping, CoverageRecords;
|
||||
auto ObjFormat = OF->getTripleObjectFormat();
|
||||
for (const auto &Section : OF->sections()) {
|
||||
StringRef Name;
|
||||
@ -65,16 +65,20 @@ int convertForTestingMain(int argc, const char *argv[]) {
|
||||
} else if (Name == llvm::getInstrProfSectionName(
|
||||
IPSK_covmap, ObjFormat, /*AddSegmentInfo=*/false)) {
|
||||
CoverageMapping = Section;
|
||||
} else if (Name == llvm::getInstrProfSectionName(
|
||||
IPSK_covfun, ObjFormat, /*AddSegmentInfo=*/false)) {
|
||||
CoverageRecords = Section;
|
||||
} else
|
||||
continue;
|
||||
++FoundSectionCount;
|
||||
}
|
||||
if (FoundSectionCount != 2)
|
||||
if (FoundSectionCount != 3)
|
||||
return 1;
|
||||
|
||||
// Get the contents of the given sections.
|
||||
uint64_t ProfileNamesAddress = ProfileNames.getAddress();
|
||||
StringRef CoverageMappingData;
|
||||
StringRef CoverageRecordsData;
|
||||
StringRef ProfileNamesData;
|
||||
if (Expected<StringRef> E = CoverageMapping.getContents())
|
||||
CoverageMappingData = *E;
|
||||
@ -82,6 +86,12 @@ int convertForTestingMain(int argc, const char *argv[]) {
|
||||
consumeError(E.takeError());
|
||||
return 1;
|
||||
}
|
||||
if (Expected<StringRef> E = CoverageRecords.getContents())
|
||||
CoverageRecordsData = *E;
|
||||
else {
|
||||
consumeError(E.takeError());
|
||||
return 1;
|
||||
}
|
||||
if (Expected<StringRef> E = ProfileNames.getContents())
|
||||
ProfileNamesData = *E;
|
||||
else {
|
||||
@ -104,6 +114,10 @@ int convertForTestingMain(int argc, const char *argv[]) {
|
||||
for (unsigned Pad = offsetToAlignment(OS.tell(), Align(8)); Pad; --Pad)
|
||||
OS.write(uint8_t(0));
|
||||
OS << CoverageMappingData;
|
||||
// Coverage records data is expected to have an alignment of 8.
|
||||
for (unsigned Pad = offsetToAlignment(OS.tell(), Align(8)); Pad; --Pad)
|
||||
OS.write(uint8_t(0));
|
||||
OS << CoverageRecordsData;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user