Index: include/llvm/ProfileData/InstrProf.h =================================================================== --- include/llvm/ProfileData/InstrProf.h +++ include/llvm/ProfileData/InstrProf.h @@ -54,39 +54,29 @@ class Module; /// Return the name of data section containing profile counter variables. -inline StringRef getInstrProfCountersSectionName(bool AddSegment) { - return AddSegment ? "__DATA," INSTR_PROF_CNTS_SECT_NAME_STR - : INSTR_PROF_CNTS_SECT_NAME_STR; -} +/// 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. +StringRef getInstrProfCountersSectionName(const Module *M = nullptr); /// Return the name of data section containing names of instrumented -/// functions. -inline StringRef getInstrProfNameSectionName(bool AddSegment) { - return AddSegment ? "__DATA," INSTR_PROF_NAME_SECT_NAME_STR - : INSTR_PROF_NAME_SECT_NAME_STR; -} +/// functions. If M is null, the target platform is assumed to be the same as +/// the host machine, nor will segment prefix be added. +StringRef getInstrProfNameSectionName(const Module *M = nullptr); /// Return the name of the data section containing per-function control -/// data. -inline StringRef getInstrProfDataSectionName(bool AddSegment) { - return AddSegment ? "__DATA," INSTR_PROF_DATA_SECT_NAME_STR - ",regular,live_support" - : INSTR_PROF_DATA_SECT_NAME_STR; -} +/// 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. +StringRef getInstrProfDataSectionName(const Module *M = nullptr); /// Return the name of data section containing pointers to value profile -/// counters/nodes. -inline StringRef getInstrProfValuesSectionName(bool AddSegment) { - return AddSegment ? "__DATA," INSTR_PROF_VALS_SECT_NAME_STR - : INSTR_PROF_VALS_SECT_NAME_STR; -} +/// 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. +StringRef getInstrProfValuesSectionName(const Module *M = nullptr); /// Return the name of data section containing nodes holdling value -/// profiling data. -inline StringRef getInstrProfVNodesSectionName(bool AddSegment) { - return AddSegment ? "__DATA," INSTR_PROF_VNODES_SECT_NAME_STR - : INSTR_PROF_VNODES_SECT_NAME_STR; -} +/// profiling 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. +StringRef getInstrProfVNodesSectionName(const Module *M = nullptr); /// Return the name profile runtime entry point to do value profiling /// for a given site. @@ -101,10 +91,7 @@ /// Return the name of the section containing function coverage mapping /// data. -inline StringRef getInstrProfCoverageSectionName(bool AddSegment) { - return AddSegment ? "__LLVM_COV," INSTR_PROF_COVMAP_SECT_NAME_STR - : INSTR_PROF_COVMAP_SECT_NAME_STR; -} +StringRef getInstrProfCoverageSectionName(const Module *M = nullptr); /// Return the name prefix of variables containing instrumented function names. inline StringRef getInstrProfNameVarPrefix() { return "__profn_"; } Index: include/llvm/ProfileData/InstrProfData.inc =================================================================== --- include/llvm/ProfileData/InstrProfData.inc +++ include/llvm/ProfileData/InstrProfData.inc @@ -622,17 +622,47 @@ * specified via command line. */ #define INSTR_PROF_PROFILE_NAME_VAR __llvm_profile_filename +/* section name strings common to all targets other + than WIN32 */ +#define INSTR_PROF_DATA_COMMON __llvm_prf_data +#define INSTR_PROF_NAME_COMMON __llvm_prf_names +#define INSTR_PROF_CNTS_COMMON __llvm_prf_cnts +#define INSTR_PROF_VALS_COMMON __llvm_prf_vals +#define INSTR_PROF_VNODES_COMMON __llvm_prf_vnds +#define INSTR_PROF_COVMAP_COMMON __llvm_covmap +/* Win32 */ +#define INSTR_PROF_DATA_COFF .lprfd +#define INSTR_PROF_NAME_COFF .lprfn +#define INSTR_PROF_CNTS_COFF .lprfc +#define INSTR_PROF_VALS_COFF .lprfv +#define INSTR_PROF_VNODES_COFF .lprfnd +#define INSTR_PROF_COVMAP_COFF .lcovmap + +#ifdef _WIN32 +/* Runtime section names and name strings. */ +#define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_DATA_COFF +#define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_NAME_COFF +#define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_CNTS_COFF +/* Array of pointers. Each pointer points to a list + * of value nodes associated with one value site. + */ +#define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_VALS_COFF +/* Value profile nodes section. */ +#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COFF +#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COFF +#else /* Runtime section names and name strings. */ -#define INSTR_PROF_DATA_SECT_NAME __llvm_prf_data -#define INSTR_PROF_NAME_SECT_NAME __llvm_prf_names -#define INSTR_PROF_CNTS_SECT_NAME __llvm_prf_cnts +#define INSTR_PROF_DATA_SECT_NAME INSTR_PROF_DATA_COMMON +#define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_NAME_COMMON +#define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_CNTS_COMMON /* Array of pointers. Each pointer points to a list * of value nodes associated with one value site. */ -#define INSTR_PROF_VALS_SECT_NAME __llvm_prf_vals +#define INSTR_PROF_VALS_SECT_NAME INSTR_PROF_VALS_COMMON /* Value profile nodes section. */ -#define INSTR_PROF_VNODES_SECT_NAME __llvm_prf_vnds -#define INSTR_PROF_COVMAP_SECT_NAME __llvm_covmap +#define INSTR_PROF_VNODES_SECT_NAME INSTR_PROF_VNODES_COMMON +#define INSTR_PROF_COVMAP_SECT_NAME INSTR_PROF_COVMAP_COMMON +#endif #define INSTR_PROF_DATA_SECT_NAME_STR \ INSTR_PROF_QUOTE(INSTR_PROF_DATA_SECT_NAME) Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -133,7 +133,7 @@ // // .section .eh_frame,"a",@progbits - if (Name == getInstrProfCoverageSectionName(false)) + if (Name == getInstrProfCoverageSectionName(nullptr)) 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 @@ -648,11 +648,11 @@ : support::endianness::big; // Look for the sections that we are interested in. - auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName(false)); + auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName()); if (auto E = NamesSection.takeError()) return E; auto CoverageSection = - lookupSection(*OF, getInstrProfCoverageSectionName(false)); + lookupSection(*OF, getInstrProfCoverageSectionName(nullptr)); if (auto E = CoverageSection.takeError()) return E; Index: lib/ProfileData/InstrProf.cpp =================================================================== --- lib/ProfileData/InstrProf.cpp +++ lib/ProfileData/InstrProf.cpp @@ -138,6 +138,123 @@ namespace llvm { +#define ADD_PREFIX(AddSegement, SectName) \ + (AddSegment ? "__DATA," SectName : SectName) + +#define ADD_PREFIX2(AddSegement, SectName) \ + (AddSegment ? "__DATA," SectName ",regular,live_support" : SectName) + +#define ADD_PREFIX3(AddSegement, SectName) \ + (AddSegment ? "__LLVM_COV," SectName : SectName) + +/// Return the name of data section containing profile counter variables. +StringRef getInstrProfCountersSectionName(const Module *M) { + bool AddSegment = (M && Triple(M->getTargetTriple()).isOSBinFormatMachO()); + StringRef sect_name = ADD_PREFIX(AddSegment, INSTR_PROF_CNTS_SECT_NAME_STR); + // If we have triple info, use it: + if (M) { + if (Triple(M->getTargetTriple()).isOSBinFormatCOFF()) { + sect_name = + ADD_PREFIX(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COFF)); + } else { + sect_name = + ADD_PREFIX(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON)); + } + } + return sect_name; +} + +/// Return the name of data section containing names of instrumented +/// functions. +StringRef getInstrProfNameSectionName(const Module *M) { + bool AddSegment = (M && Triple(M->getTargetTriple()).isOSBinFormatMachO()); + StringRef sect_name = ADD_PREFIX(AddSegment, INSTR_PROF_NAME_SECT_NAME_STR); + // If we have triple info, use it: + if (M) { + if (Triple(M->getTargetTriple()).isOSBinFormatCOFF()) { + sect_name = + ADD_PREFIX(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_NAME_COFF)); + } else { + sect_name = + ADD_PREFIX(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON)); + } + } + return sect_name; +} + +/// Return the name of the data section containing per-function control +/// data. +StringRef getInstrProfDataSectionName(const Module *M) { + bool AddSegment = (M && Triple(M->getTargetTriple()).isOSBinFormatMachO()); + StringRef sect_name = ADD_PREFIX2(AddSegment, INSTR_PROF_DATA_SECT_NAME_STR); + // If we have triple info, use it: + if (M) { + if (Triple(M->getTargetTriple()).isOSBinFormatCOFF()) { + sect_name = + ADD_PREFIX2(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_DATA_COFF)); + } else { + sect_name = + ADD_PREFIX2(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_DATA_COMMON)); + } + } + return sect_name; +} + +/// Return the name of data section containing pointers to value profile +/// counters/nodes. +StringRef getInstrProfValuesSectionName(const Module *M) { + bool AddSegment = (M && Triple(M->getTargetTriple()).isOSBinFormatMachO()); + StringRef sect_name = ADD_PREFIX(AddSegment, INSTR_PROF_VALS_SECT_NAME_STR); + // If we have triple info, use it: + if (M) { + if (Triple(M->getTargetTriple()).isOSBinFormatCOFF()) { + sect_name = + ADD_PREFIX(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_VALS_COFF)); + } else { + sect_name = + ADD_PREFIX(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON)); + } + } + return sect_name; +} + +/// Return the name of data section containing nodes holdling value +/// profiling data. +StringRef getInstrProfVNodesSectionName(const Module *M) { + bool AddSegment = (M && Triple(M->getTargetTriple()).isOSBinFormatMachO()); + StringRef sect_name = ADD_PREFIX(AddSegment, INSTR_PROF_VNODES_SECT_NAME_STR); + // If we have triple info, use it: + if (M) { + if (Triple(M->getTargetTriple()).isOSBinFormatCOFF()) { + sect_name = + ADD_PREFIX(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COFF)); + } else { + sect_name = + ADD_PREFIX(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON)); + } + } + return sect_name; +} + +/// Return the name of the section containing function coverage mapping +/// data. +StringRef getInstrProfCoverageSectionName(const Module *M) { + bool AddSegment = (M && Triple(M->getTargetTriple()).isOSBinFormatMachO()); + StringRef sect_name = + ADD_PREFIX3(AddSegment, INSTR_PROF_COVMAP_SECT_NAME_STR); + // If we have triple info, use it: + if (M) { + if (Triple(M->getTargetTriple()).isOSBinFormatCOFF()) { + sect_name = + ADD_PREFIX3(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COFF)); + } else { + sect_name = + ADD_PREFIX3(AddSegment, INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON)); + } + } + return sect_name; +} + void SoftInstrProfErrors::addError(instrprof_error IE) { if (IE == instrprof_error::success) return; Index: lib/Transforms/Instrumentation/InstrProfiling.cpp =================================================================== --- lib/Transforms/Instrumentation/InstrProfiling.cpp +++ lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -146,22 +146,22 @@ /// Get the section name for the counter variables. StringRef InstrProfiling::getCountersSection() const { - return getInstrProfCountersSectionName(isMachO()); + return getInstrProfCountersSectionName(M); } /// Get the section name for the name variables. StringRef InstrProfiling::getNameSection() const { - return getInstrProfNameSectionName(isMachO()); + return getInstrProfNameSectionName(M); } /// Get the section name for the profile data variables. StringRef InstrProfiling::getDataSection() const { - return getInstrProfDataSectionName(isMachO()); + return getInstrProfDataSectionName(M); } /// Get the section name for the coverage mapping data. StringRef InstrProfiling::getCoverageSection() const { - return getInstrProfCoverageSectionName(isMachO()); + return getInstrProfCoverageSectionName(M); } static InstrProfIncrementInst *castToIncrementInst(Instruction *Instr) { @@ -462,7 +462,7 @@ 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 @@ 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); } Index: lib/Transforms/Instrumentation/ThreadSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/ThreadSanitizer.cpp +++ lib/Transforms/Instrumentation/ThreadSanitizer.cpp @@ -281,7 +281,7 @@ StringRef SectionName = GV->getSection(); // Check if the global is in the PGO counters section. if (SectionName.endswith(getInstrProfCountersSectionName( - /*AddSegment=*/false))) + nullptr))) return false; } Index: test/Instrumentation/InstrProfiling/PR23499.ll =================================================================== --- test/Instrumentation/InstrProfiling/PR23499.ll +++ test/Instrumentation/InstrProfiling/PR23499.ll @@ -20,8 +20,8 @@ ; COFF-NOT: __profn__Z3barIvEvv -; COFF: @__profc__Z3barIvEvv = linkonce_odr hidden global [1 x i64] zeroinitializer, section "{{.*}}__llvm_prf_cnts", comdat, align 8 -; COFF: @__profd__Z3barIvEvv = linkonce_odr hidden global { i64, i64, i64*, i8*, i8*, i32, [2 x i16] } { i64 4947693190065689389, i64 0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__Z3barIvEvv, i32 0, i32 0), i8*{{.*}}, i8* null, i32 1, [2 x i16] zeroinitializer }, section "{{.*}}__llvm_prf_data{{.*}}", comdat($__profc__Z3barIvEvv), align 8 +; COFF: @__profc__Z3barIvEvv = linkonce_odr hidden global [1 x i64] zeroinitializer, section "{{.*}}prfc", comdat, align 8 +; COFF: @__profd__Z3barIvEvv = linkonce_odr hidden global { i64, i64, i64*, i8*, i8*, i32, [2 x i16] } { i64 4947693190065689389, i64 0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__Z3barIvEvv, i32 0, i32 0), i8*{{.*}}, i8* null, i32 1, [2 x i16] zeroinitializer }, section "{{.*}}prfd{{.*}}", comdat($__profc__Z3barIvEvv), align 8 declare void @llvm.instrprof.increment(i8*, i64, i32, i32) #1 Index: tools/llvm-cov/TestingSupport.cpp =================================================================== --- tools/llvm-cov/TestingSupport.cpp +++ tools/llvm-cov/TestingSupport.cpp @@ -52,9 +52,9 @@ StringRef Name; if (Section.getName(Name)) return 1; - if (Name == llvm::getInstrProfNameSectionName(false)) { + if (Name == llvm::getInstrProfNameSectionName()) { ProfileNames = Section; - } else if (Name == llvm::getInstrProfCoverageSectionName(false)) { + } else if (Name == llvm::getInstrProfCoverageSectionName()) { CoverageMapping = Section; } else continue;