Skip to content

Commit c68f363

Browse files
committed
[Coverage] Do not move PGO name pointers into __llvm_prf_names
Instead, pass name pointers to InstrProfiling::lowerCoverageData() using the new API (via getCoverageUnusedNamesVarName). This ensures that we don't emit an uncompressed *and* a compressed version of all function names into the module, fixing rdar://problem/25493310. (cherry picked from commit 668d81f)
1 parent 06c6546 commit c68f363

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

lib/IRGen/GenCoverage.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ static StringRef getCoverageSection(IRGenModule &IGM) {
4040
return llvm::getInstrProfCoverageSectionName(isMachO(IGM));
4141
}
4242

43-
static StringRef getProfNamesSection(IRGenModule &IGM) {
44-
return llvm::getInstrProfNameSectionName(isMachO(IGM));
45-
}
46-
4743
void IRGenModule::emitCoverageMapping() {
4844
const auto &Mappings = getSILModule().getCoverageMapList();
4945
// If there aren't any coverage maps, there's nothing to emit.
@@ -77,6 +73,7 @@ void IRGenModule::emitCoverageMapping() {
7773
// Now we need to build up the list of function records.
7874
llvm::LLVMContext &Ctx = LLVMContext;
7975
auto *Int32Ty = llvm::Type::getInt32Ty(Ctx);
76+
auto *Int8PtrTy = llvm::Type::getInt8PtrTy(Ctx);
8077

8178
llvm::Type *FunctionRecordTypes[] = {
8279
#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) LLVMType,
@@ -88,6 +85,7 @@ void IRGenModule::emitCoverageMapping() {
8885
llvm::StructType::get(Ctx, llvm::makeArrayRef(FunctionRecordTypes),
8986
/*isPacked=*/true);
9087

88+
std::vector<llvm::Constant *> FunctionNames;
9189
std::vector<llvm::Constant *> FunctionRecords;
9290
std::vector<CounterMappingRegion> Regions;
9391
for (const auto &M : Mappings) {
@@ -110,13 +108,7 @@ void IRGenModule::emitCoverageMapping() {
110108
M.getFile());
111109
llvm::GlobalVariable *NamePtr = llvm::createPGOFuncNameVar(
112110
*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));
120112

121113
CurrentSize = OS.str().size();
122114
unsigned MappingLen = CurrentSize - PrevSize;
@@ -181,6 +173,13 @@ void IRGenModule::emitCoverageMapping() {
181173
CovDataVal, llvm::getCoverageMappingVarName());
182174
CovData->setSection(getCoverageSection(*this));
183175
CovData->setAlignment(8);
184-
185176
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+
}
186185
}

0 commit comments

Comments
 (0)