[Profile] PE binary coverage bug fix
PR/32584
Differential Revision: https://reviews.llvm.org/D32023
llvm-svn: 300277
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 05c5b28..515f19a 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -648,11 +648,15 @@
: support::endianness::big;
// Look for the sections that we are interested in.
- auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName(false));
+ // TODO: with the current getInstrProfXXXSectionName interfaces, the
+ // the coverage reader host tool is limited to read coverage section on
+ // binaries with compatible profile section naming scheme as the host
+ // platform. Currently, COFF format binaries have different section
+ // naming scheme from the all the rest.
+ auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName());
if (auto E = NamesSection.takeError())
return E;
- auto CoverageSection =
- lookupSection(*OF, getInstrProfCoverageSectionName(false));
+ auto CoverageSection = lookupSection(*OF, getInstrProfCoverageSectionName());
if (auto E = CoverageSection.takeError())
return E;
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 0ec3fce..d66d25e 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -136,8 +136,92 @@
return *ErrorCategory;
}
+namespace {
+
+enum InstrProfSectKind {
+#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
+ Prefix) \
+ Kind,
+#include "llvm/ProfileData/InstrProfData.inc"
+};
+
+const char *InstrProfSectName[] = {
+#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
+ Prefix) \
+ SectName,
+#include "llvm/ProfileData/InstrProfData.inc"
+};
+
+const char *InstrProfSectNameCommon[] = {
+#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
+ Prefix) \
+ SectNameCommon,
+#include "llvm/ProfileData/InstrProfData.inc"
+};
+
+const char *InstrProfSectNameCoff[] = {
+#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
+ Prefix) \
+ SectNameCoff,
+#include "llvm/ProfileData/InstrProfData.inc"
+};
+
+const char *InstrProfSectNamePrefix[] = {
+#define INSTR_PROF_SECT_ENTRY(Kind, SectName, SectNameCommon, SectNameCoff, \
+ Prefix) \
+ Prefix,
+#include "llvm/ProfileData/InstrProfData.inc"
+};
+
+std::string getInstrProfSectionName(const Module *M, InstrProfSectKind Kind) {
+
+ if (!M)
+ return InstrProfSectName[Kind];
+
+ bool AddSegment = Triple(M->getTargetTriple()).isOSBinFormatMachO();
+ std::string SectName;
+ if (Triple(M->getTargetTriple()).isOSBinFormatCOFF())
+ SectName = InstrProfSectNameCoff[Kind];
+ else
+ SectName = InstrProfSectNameCommon[Kind];
+
+ if (AddSegment) {
+ SectName = InstrProfSectNamePrefix[Kind] + SectName;
+ if (Kind == IPSK_data) {
+ SectName += ",regular,live_support";
+ }
+ }
+ return SectName;
+}
+
+} // namespace
+
namespace llvm {
+std::string getInstrProfCountersSectionName(const Module *M) {
+ return getInstrProfSectionName(M, IPSK_cnts);
+}
+
+std::string getInstrProfNameSectionName(const Module *M) {
+ return getInstrProfSectionName(M, IPSK_name);
+}
+
+std::string getInstrProfDataSectionName(const Module *M) {
+ return getInstrProfSectionName(M, IPSK_data);
+}
+
+std::string getInstrProfValuesSectionName(const Module *M) {
+ return getInstrProfSectionName(M, IPSK_vals);
+}
+
+std::string getInstrProfVNodesSectionName(const Module *M) {
+ return getInstrProfSectionName(M, IPSK_vnodes);
+}
+
+std::string getInstrProfCoverageSectionName(const Module *M) {
+ return getInstrProfSectionName(M, IPSK_covmap);
+}
+
void SoftInstrProfErrors::addError(instrprof_error IE) {
if (IE == instrprof_error::success)
return;