diff options
author | Xinliang David Li <davidxl@google.com> | 2017-04-13 23:37:12 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2017-04-13 23:37:12 +0000 |
commit | 57dea2d3591791147436dea198a13f7c3c82caea (patch) | |
tree | 64a6e9f9e8dd48fcb53b9a18dfc47643c3cf67b4 /llvm/lib | |
parent | c5779460f4cbea38dc77911b667a6d76c79c1a3f (diff) | |
download | bcm5719-llvm-57dea2d3591791147436dea198a13f7c3c82caea.tar.gz bcm5719-llvm-57dea2d3591791147436dea198a13f7c3c82caea.zip |
[Profile] PE binary coverage bug fix
PR/32584
Differential Revision: https://reviews.llvm.org/D32023
llvm-svn: 300277
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 84 | ||||
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | 20 | ||||
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp | 3 |
5 files changed, 105 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 78afeda67db..2de5d1b780e 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -133,7 +133,9 @@ getELFKindForNamedSection(StringRef Name, SectionKind K) { // // .section .eh_frame,"a",@progbits - if (Name == getInstrProfCoverageSectionName(false)) + // TODO: to support Win->ELF cross compilation with coverage properly, + // need to pass the module pointer to the following call. + if (Name == getInstrProfCoverageSectionName()) return SectionKind::getMetadata(); if (Name.empty() || Name[0] != '.') return K; diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp index 05c5b28d7a0..515f19a3b40 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -648,11 +648,15 @@ static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer, : 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 0ec3fce4b23..d66d25eb190 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -136,8 +136,92 @@ const std::error_category &llvm::instrprof_category() { 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; diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index 1f8bcb9a330..c47467f1a84 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -145,23 +145,23 @@ bool InstrProfiling::isMachO() const { } /// Get the section name for the counter variables. -StringRef InstrProfiling::getCountersSection() const { - return getInstrProfCountersSectionName(isMachO()); +std::string InstrProfiling::getCountersSection() const { + return getInstrProfCountersSectionName(M); } /// Get the section name for the name variables. -StringRef InstrProfiling::getNameSection() const { - return getInstrProfNameSectionName(isMachO()); +std::string InstrProfiling::getNameSection() const { + return getInstrProfNameSectionName(M); } /// Get the section name for the profile data variables. -StringRef InstrProfiling::getDataSection() const { - return getInstrProfDataSectionName(isMachO()); +std::string InstrProfiling::getDataSection() const { + return getInstrProfDataSectionName(M); } /// Get the section name for the coverage mapping data. -StringRef InstrProfiling::getCoverageSection() const { - return getInstrProfCoverageSectionName(isMachO()); +std::string InstrProfiling::getCoverageSection() const { + return getInstrProfCoverageSectionName(M); } static InstrProfIncrementInst *castToIncrementInst(Instruction *Instr) { @@ -462,7 +462,7 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) { Constant::getNullValue(ValuesTy), getVarName(Inc, getInstrProfValuesVarPrefix())); ValuesVar->setVisibility(NamePtr->getVisibility()); - ValuesVar->setSection(getInstrProfValuesSectionName(isMachO())); + ValuesVar->setSection(getInstrProfValuesSectionName(M)); ValuesVar->setAlignment(8); ValuesVar->setComdat(ProfileVarsComdat); ValuesPtrExpr = @@ -557,7 +557,7 @@ void InstrProfiling::emitVNodes() { auto *VNodesVar = new GlobalVariable( *M, VNodesTy, false, GlobalValue::PrivateLinkage, Constant::getNullValue(VNodesTy), getInstrProfVNodesVarName()); - VNodesVar->setSection(getInstrProfVNodesSectionName(isMachO())); + VNodesVar->setSection(getInstrProfVNodesSectionName(M)); UsedVars.push_back(VNodesVar); } diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp index 2ec6d09594d..c6a6f954d13 100644 --- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp @@ -280,8 +280,7 @@ static bool shouldInstrumentReadWriteFromAddress(Value *Addr) { if (GV->hasSection()) { StringRef SectionName = GV->getSection(); // Check if the global is in the PGO counters section. - if (SectionName.endswith(getInstrProfCountersSectionName( - /*AddSegment=*/false))) + if (SectionName.endswith(getInstrProfCountersSectionName())) return false; } |