25
25
#include " llvm/Object/MachOUniversal.h"
26
26
#include " llvm/Object/ObjectFile.h"
27
27
#include " llvm/ProfileData/InstrProf.h"
28
- #include " llvm/ProfileData/InstrProfReader.h"
29
28
#include " llvm/Support/Casting.h"
30
29
#include " llvm/Support/Compression.h"
31
30
#include " llvm/Support/Debug.h"
@@ -1022,23 +1021,9 @@ static Expected<std::vector<SectionRef>> lookupSections(ObjectFile &OF,
1022
1021
return Sections;
1023
1022
}
1024
1023
1025
- static Error getProfileNamesFromDebugInfo (StringRef FileName,
1026
- InstrProfSymtab &ProfileNames) {
1027
- std::unique_ptr<InstrProfCorrelator> Correlator;
1028
- if (auto E = InstrProfCorrelator::get (FileName).moveInto (Correlator))
1029
- return E;
1030
- if (auto E = Correlator->correlateCovUnusedFuncNames (0 ))
1031
- return E;
1032
- if (auto E = ProfileNames.create (
1033
- StringRef (Correlator->getCovUnusedFuncNamesPointer (),
1034
- Correlator->getCovUnusedFuncNamesSize ())))
1035
- return E;
1036
- return Error::success ();
1037
- }
1038
-
1039
1024
static Expected<std::unique_ptr<BinaryCoverageReader>>
1040
1025
loadBinaryFormat (std::unique_ptr<Binary> Bin, StringRef Arch,
1041
- InstrProfSymtab &ProfSymTab, StringRef CompilationDir = " " ,
1026
+ StringRef CompilationDir = " " ,
1042
1027
object::BuildIDRef *BinaryID = nullptr ) {
1043
1028
std::unique_ptr<ObjectFile> OF;
1044
1029
if (auto *Universal = dyn_cast<MachOUniversalBinary>(Bin.get ())) {
@@ -1067,30 +1052,11 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
1067
1052
1068
1053
// Look for the sections that we are interested in.
1069
1054
auto ObjFormat = OF->getTripleObjectFormat ();
1070
- // Without debug info correlation, all function names are stored in the
1071
- // binary's profile name section.
1072
- // When debug info correlation is enabled, instrumented function names are
1073
- // stored in the indexed profile file, and unused function names are stored in
1074
- // the binary's debug info.
1075
- InstrProfSymtab ProfileNames = ProfSymTab;
1076
1055
auto NamesSection =
1077
1056
lookupSections (*OF, getInstrProfSectionName (IPSK_name, ObjFormat,
1078
- /* AddSegmentInfo=*/ false ));
1079
- if (auto E = NamesSection.takeError ()) {
1080
- if (OF->hasDebugInfo ()) {
1081
- if (auto E =
1082
- getProfileNamesFromDebugInfo (OF->getFileName (), ProfileNames))
1083
- return make_error<CoverageMapError>(coveragemap_error::malformed);
1084
- }
1085
- consumeError (std::move (E));
1086
- } else {
1087
- std::vector<SectionRef> NamesSectionRefs = *NamesSection;
1088
- if (NamesSectionRefs.size () != 1 )
1089
- return make_error<CoverageMapError>(coveragemap_error::malformed);
1090
- if (Error E = ProfileNames.create (NamesSectionRefs.back ()))
1091
- return std::move (E);
1092
- }
1093
-
1057
+ /* AddSegmentInfo=*/ false ));
1058
+ if (auto E = NamesSection.takeError ())
1059
+ return std::move (E);
1094
1060
auto CoverageSection =
1095
1061
lookupSections (*OF, getInstrProfSectionName (IPSK_covmap, ObjFormat,
1096
1062
/* AddSegmentInfo=*/ false ));
@@ -1105,6 +1071,15 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
1105
1071
return CoverageMappingOrErr.takeError ();
1106
1072
StringRef CoverageMapping = CoverageMappingOrErr.get ();
1107
1073
1074
+ InstrProfSymtab ProfileNames;
1075
+ std::vector<SectionRef> NamesSectionRefs = *NamesSection;
1076
+ if (NamesSectionRefs.size () != 1 )
1077
+ return make_error<CoverageMapError>(
1078
+ coveragemap_error::malformed,
1079
+ " the size of coverage mapping section is not one" );
1080
+ if (Error E = ProfileNames.create (NamesSectionRefs.back ()))
1081
+ return std::move (E);
1082
+
1108
1083
// Look for the coverage records section (Version4 only).
1109
1084
auto CoverageRecordsSections =
1110
1085
lookupSections (*OF, getInstrProfSectionName (IPSK_covfun, ObjFormat,
@@ -1176,8 +1151,7 @@ Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
1176
1151
BinaryCoverageReader::create (
1177
1152
MemoryBufferRef ObjectBuffer, StringRef Arch,
1178
1153
SmallVectorImpl<std::unique_ptr<MemoryBuffer>> &ObjectFileBuffers,
1179
- InstrProfSymtab &ProfSymTab, StringRef CompilationDir,
1180
- SmallVectorImpl<object::BuildIDRef> *BinaryIDs) {
1154
+ StringRef CompilationDir, SmallVectorImpl<object::BuildIDRef> *BinaryIDs) {
1181
1155
std::vector<std::unique_ptr<BinaryCoverageReader>> Readers;
1182
1156
1183
1157
if (ObjectBuffer.getBuffer ().size () > sizeof (TestingFormatMagic)) {
@@ -1221,8 +1195,8 @@ BinaryCoverageReader::create(
1221
1195
}
1222
1196
1223
1197
return BinaryCoverageReader::create (
1224
- ArchiveOrErr.get ()->getMemoryBufferRef (), Arch,
1225
- ObjectFileBuffers, ProfSymTab, CompilationDir, BinaryIDs);
1198
+ ArchiveOrErr.get ()->getMemoryBufferRef (), Arch, ObjectFileBuffers,
1199
+ CompilationDir, BinaryIDs);
1226
1200
}
1227
1201
}
1228
1202
@@ -1235,8 +1209,8 @@ BinaryCoverageReader::create(
1235
1209
return ChildBufOrErr.takeError ();
1236
1210
1237
1211
auto ChildReadersOrErr = BinaryCoverageReader::create (
1238
- ChildBufOrErr.get (), Arch, ObjectFileBuffers, ProfSymTab ,
1239
- CompilationDir, BinaryIDs);
1212
+ ChildBufOrErr.get (), Arch, ObjectFileBuffers, CompilationDir ,
1213
+ BinaryIDs);
1240
1214
if (!ChildReadersOrErr)
1241
1215
return ChildReadersOrErr.takeError ();
1242
1216
for (auto &Reader : ChildReadersOrErr.get ())
@@ -1256,9 +1230,8 @@ BinaryCoverageReader::create(
1256
1230
}
1257
1231
1258
1232
object::BuildIDRef BinaryID;
1259
- auto ReaderOrErr =
1260
- loadBinaryFormat (std::move (Bin), Arch, ProfSymTab, CompilationDir,
1261
- BinaryIDs ? &BinaryID : nullptr );
1233
+ auto ReaderOrErr = loadBinaryFormat (std::move (Bin), Arch, CompilationDir,
1234
+ BinaryIDs ? &BinaryID : nullptr );
1262
1235
if (!ReaderOrErr)
1263
1236
return ReaderOrErr.takeError ();
1264
1237
Readers.push_back (std::move (ReaderOrErr.get ()));
0 commit comments