NamesVar = nullptr;
NamesSize = 0;
ProfileDataMap.clear();
+ CompilerUsedVars.clear();
UsedVars.clear();
TT = Triple(M.getTargetTriple());
ProfileDataMap[NamePtr] = PD;
// Mark the data variable as used so that it isn't stripped out.
- UsedVars.push_back(Data);
+ CompilerUsedVars.push_back(Data);
// Now that the linkage set by the FE has been passed to the data and counter
// variables, reset Name variable's linkage and visibility to private so that
// it can be removed later by the compiler.
Constant::getNullValue(VNodesTy), getInstrProfVNodesVarName());
VNodesVar->setSection(
getInstrProfSectionName(IPSK_vnodes, TT.getObjectFormat()));
+ // VNodesVar is used by runtime but not referenced via relocation by other
+ // sections. Conservatively make it linker retained.
UsedVars.push_back(VNodesVar);
}
// linker from inserting padding before the start of the names section or
// between names entries.
NamesVar->setAlignment(Align(1));
+ // NamesVar is used by runtime but not referenced via relocation by other
+ // sections. Conservatively make it linker retained.
UsedVars.push_back(NamesVar);
for (auto *NamePtr : ReferencedNames)
getInstrProfRegFuncName(), M);
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", RegisterF));
+ for (Value *Data : CompilerUsedVars)
+ if (!isa<Function>(Data))
+ IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(Data, VoidPtrTy));
for (Value *Data : UsedVars)
if (Data != NamesVar && !isa<Function>(Data))
IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(Data, VoidPtrTy));
IRB.CreateRet(Load);
// Mark the user variable as used so that it isn't stripped out.
- UsedVars.push_back(User);
+ CompilerUsedVars.push_back(User);
return true;
}
// or discarded as a unit, so llvm.compiler.used is sufficient. Otherwise,
// conservatively make all of them retained by the linker.
if (TT.isOSBinFormatELF())
- appendToCompilerUsed(*M, UsedVars);
+ appendToCompilerUsed(*M, CompilerUsedVars);
else
- appendToUsed(*M, UsedVars);
+ appendToUsed(*M, CompilerUsedVars);
+
+ // We do not add proper references from used metadata sections to NamesVar and
+ // VNodesVar, so we have to be conservative and place them in llvm.used
+ // regardless of the target,
+ appendToUsed(*M, UsedVars);
}
void InstrProfiling::emitInitialization() {
; DYN-NOT: @__profvp_foo
; DYN-NOT: @__llvm_prf_vnodes
+;; __llvm_prf_vnodes and __llvm_prf_nm are not referenced by other metadata sections.
+;; We have to conservatively place them in llvm.used.
+; STATIC: @llvm.used = appending global
+; STATIC-SAME: @__llvm_prf_vnodes
+; STATIC-SAME: @__llvm_prf_nm
+
; STATIC: call void @__llvm_profile_instrument_target(i64 %3, i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_foo to i8*), i32 0)
; STATIC-EXT: call void @__llvm_profile_instrument_target(i64 %3, i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_foo to i8*), i32 zeroext 0)
; STATIC-SEXT: call void @__llvm_profile_instrument_target(i64 %3, i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [2 x i16] }* @__profd_foo to i8*), i32 signext 0)