@@ -40,10 +40,6 @@ static StringRef getCoverageSection(IRGenModule &IGM) {
40
40
return llvm::getInstrProfCoverageSectionName (isMachO (IGM));
41
41
}
42
42
43
- static StringRef getProfNamesSection (IRGenModule &IGM) {
44
- return llvm::getInstrProfNameSectionName (isMachO (IGM));
45
- }
46
-
47
43
void IRGenModule::emitCoverageMapping () {
48
44
const auto &Mappings = getSILModule ().getCoverageMapList ();
49
45
// If there aren't any coverage maps, there's nothing to emit.
@@ -77,6 +73,7 @@ void IRGenModule::emitCoverageMapping() {
77
73
// Now we need to build up the list of function records.
78
74
llvm::LLVMContext &Ctx = LLVMContext;
79
75
auto *Int32Ty = llvm::Type::getInt32Ty (Ctx);
76
+ auto *Int8PtrTy = llvm::Type::getInt8PtrTy (Ctx);
80
77
81
78
llvm::Type *FunctionRecordTypes[] = {
82
79
#define COVMAP_FUNC_RECORD (Type, LLVMType, Name, Init ) LLVMType,
@@ -88,6 +85,7 @@ void IRGenModule::emitCoverageMapping() {
88
85
llvm::StructType::get (Ctx, llvm::makeArrayRef (FunctionRecordTypes),
89
86
/* isPacked=*/ true );
90
87
88
+ std::vector<llvm::Constant *> FunctionNames;
91
89
std::vector<llvm::Constant *> FunctionRecords;
92
90
std::vector<CounterMappingRegion> Regions;
93
91
for (const auto &M : Mappings) {
@@ -110,13 +108,7 @@ void IRGenModule::emitCoverageMapping() {
110
108
M.getFile ());
111
109
llvm::GlobalVariable *NamePtr = llvm::createPGOFuncNameVar (
112
110
*getModule (), llvm::GlobalValue::LinkOnceAnyLinkage, NameValue);
113
-
114
- // The instr-profiling pass in llvm typically sets the function name ptr's
115
- // section. We do it here because (1) SIL's int_instrprof_increment does not
116
- // use this exact GlobalVariable, so llvm misses it and (2) we shouldn't
117
- // expose all name ptrs to llvm via the getCoverageUnusedNamesVarName() API.
118
- NamePtr->setSection (getProfNamesSection (*this ));
119
- NamePtr->setAlignment (1 );
111
+ FunctionNames.push_back (llvm::ConstantExpr::getBitCast (NamePtr, Int8PtrTy));
120
112
121
113
CurrentSize = OS.str ().size ();
122
114
unsigned MappingLen = CurrentSize - PrevSize;
@@ -181,6 +173,13 @@ void IRGenModule::emitCoverageMapping() {
181
173
CovDataVal, llvm::getCoverageMappingVarName ());
182
174
CovData->setSection (getCoverageSection (*this ));
183
175
CovData->setAlignment (8 );
184
-
185
176
addUsedGlobal (CovData);
177
+
178
+ if (!FunctionNames.empty ()) {
179
+ auto *NamesArrTy = llvm::ArrayType::get (Int8PtrTy, FunctionNames.size ());
180
+ auto *NamesArrVal = llvm::ConstantArray::get (NamesArrTy, FunctionNames);
181
+ new llvm::GlobalVariable (*getModule (), NamesArrTy, true ,
182
+ llvm::GlobalValue::InternalLinkage, NamesArrVal,
183
+ llvm::getCoverageUnusedNamesVarName ());
184
+ }
186
185
}
0 commit comments