Index: lib/CodeGen/CoverageMappingGen.h =================================================================== --- lib/CodeGen/CoverageMappingGen.h +++ lib/CodeGen/CoverageMappingGen.h @@ -54,6 +54,7 @@ CoverageSourceInfo &SourceInfo; llvm::SmallDenseMap FileEntries; std::vector FunctionRecords; + std::vector FunctionNames; llvm::StructType *FunctionRecordTy; std::string CoverageMappings; Index: lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- lib/CodeGen/CoverageMappingGen.cpp +++ lib/CodeGen/CoverageMappingGen.cpp @@ -929,6 +929,8 @@ }; FunctionRecords.push_back(llvm::ConstantStruct::get( FunctionRecordTy, makeArrayRef(FunctionRecordVals))); + FunctionNames.push_back( + llvm::ConstantExpr::getBitCast(NamePtr, llvm::Type::getInt8PtrTy(Ctx))); CoverageMappings += CoverageMapping; if (CGM.getCodeGenOpts().DumpCoverageMapping) { @@ -1023,6 +1025,15 @@ // Make sure the data doesn't get deleted. CGM.addUsedGlobal(CovData); + // Create the deferred function records array + auto NamesArrTy = + llvm::ArrayType::get(llvm::Type::getInt8PtrTy(Ctx), FunctionNames.size()); + auto NamesArrVal = llvm::ConstantArray::get(NamesArrTy, FunctionNames); + // This variable will *NOT* be emitted to the object file. It is used + // to pass the list of names referenced to codegen. + new llvm::GlobalVariable(CGM.getModule(), NamesArrTy, true, + llvm::GlobalValue::InternalLinkage, NamesArrVal, + llvm::getCoverageNamesVarName()); } unsigned CoverageMappingModuleGen::getFileID(const FileEntry *File) {