Index: include/llvm/ProfileData/InstrProf.h =================================================================== --- include/llvm/ProfileData/InstrProf.h +++ include/llvm/ProfileData/InstrProf.h @@ -63,11 +63,21 @@ /// the host machine, nor will segment prefix be added. std::string getInstrProfNameSectionName(const Module *M = nullptr); +/// Similar to the above, but used by host tool (e.g, coverage) which has +/// object format information. The section name returned is not prefixed +/// with segment name. +std::string getInstrProfNameSectionName(bool isCoff); + /// Return the name of the data section containing per-function control /// data. If M is null, the target platform is assumed to be the same as /// the host machine, and the segment prefix will not be added. std::string getInstrProfDataSectionName(const Module *M = nullptr); +/// Similar to the above, but used by host tool (e.g, coverage) which has +/// object format information. The section name returned is not prefixed +/// with segment name. +std::string getInstrProfDataSectionName(bool isCoff); + /// Return the name of data section containing pointers to value profile /// counters/nodes. If M is null, the target platform is assumed to be /// the same as the host machine, and the segment prefix will not be added. @@ -92,6 +102,10 @@ /// Return the name of the section containing function coverage mapping /// data. std::string getInstrProfCoverageSectionName(const Module *M = nullptr); +/// Similar to the above, but used by host tool (e.g, coverage) which has +/// object format information. The section name returned is not prefixed +/// with segment name. +std::string getInstrProfCoverageSectionName(bool isCoff); /// Return the name prefix of variables containing instrumented function names. inline StringRef getInstrProfNameVarPrefix() { return "__profn_"; } Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -132,10 +132,8 @@ // section(".eh_frame") gcc will produce: // // .section .eh_frame,"a",@progbits - - // TODO: to support Win->ELF cross compilation with coverage properly, - // need to pass the module pointer to the following call. - if (Name == getInstrProfCoverageSectionName()) + + if (Name == getInstrProfCoverageSectionName(false /*not coff*/)) return SectionKind::getMetadata(); if (Name.empty() || Name[0] != '.') return K; Index: lib/ProfileData/Coverage/CoverageMappingReader.cpp =================================================================== --- lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -653,10 +653,12 @@ // 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()); + bool isCoff = (cast(OF.get()) != nullptr); + auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName(isCoff)); if (auto E = NamesSection.takeError()) return E; - auto CoverageSection = lookupSection(*OF, getInstrProfCoverageSectionName()); + auto CoverageSection = + lookupSection(*OF, getInstrProfCoverageSectionName(isCoff)); if (auto E = CoverageSection.takeError()) return E; Index: lib/ProfileData/InstrProf.cpp =================================================================== --- lib/ProfileData/InstrProf.cpp +++ lib/ProfileData/InstrProf.cpp @@ -173,8 +173,12 @@ #include "llvm/ProfileData/InstrProfData.inc" }; -std::string getInstrProfSectionName(const Module *M, InstrProfSectKind Kind) { +std::string getInstrProfSectionName(bool isCoff, InstrProfSectKind Kind) { + return isCoff ? InstrProfSectNameCoff[Kind] + : InstrProfSectNameCommon[Kind]; +} +std::string getInstrProfSectionName(const Module *M, InstrProfSectKind Kind) { if (!M) return InstrProfSectName[Kind]; @@ -206,10 +210,18 @@ return getInstrProfSectionName(M, IPSK_name); } +std::string getInstrProfNameSectionName(bool isCoff) { + return getInstrProfSectionName(isCoff, IPSK_name); +} + std::string getInstrProfDataSectionName(const Module *M) { return getInstrProfSectionName(M, IPSK_data); } +std::string getInstrProfDataSectionName(bool isCoff) { + return getInstrProfSectionName(isCoff, IPSK_data); +} + std::string getInstrProfValuesSectionName(const Module *M) { return getInstrProfSectionName(M, IPSK_vals); } @@ -222,6 +234,10 @@ return getInstrProfSectionName(M, IPSK_covmap); } +std::string getInstrProfCoverageSectionName(bool isCoff) { + return getInstrProfSectionName(isCoff, IPSK_covmap); +} + void SoftInstrProfErrors::addError(instrprof_error IE) { if (IE == instrprof_error::success) return;