Add llvm.gcov metadata only if profiler is enabled

This commit is contained in:
Marco Castelluccio 2017-06-04 17:50:25 +01:00
parent 60524c55e9
commit a1ca5f689f

View File

@ -806,28 +806,30 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
0,
split_name.as_ptr() as *const _);
let cu_desc_metadata = llvm::LLVMRustMetadataAsValue(debug_context.llcontext,
unit_metadata);
if sess.opts.debugging_opts.profile {
let cu_desc_metadata = llvm::LLVMRustMetadataAsValue(debug_context.llcontext,
unit_metadata);
let gcov_cu_info = [
// Ideally we would be using the three-element form of !llvm.gcov metadata,
// which allows us to specify gcno/gcda files explicitly, but that's only
// available in LLVM 3.9+; so we rely on LLVM chopping off the extension
// and replacing it with gcno/gcda, instead.
path_to_mdstring(debug_context.llcontext,
&scc.output_filenames().with_extension("gcno")),
// path_to_mdstring(debug_context.llcontext,
// &scc.output_filenames().with_extension("gcda")),
cu_desc_metadata,
];
let gcov_metadata = llvm::LLVMMDNodeInContext(debug_context.llcontext,
gcov_cu_info.as_ptr(),
gcov_cu_info.len() as c_uint);
let gcov_cu_info = [
// Ideally we would be using the three-element form of !llvm.gcov metadata,
// which allows us to specify gcno/gcda files explicitly, but that's only
// available in LLVM 3.9+; so we rely on LLVM chopping off the extension
// and replacing it with gcno/gcda, instead.
path_to_mdstring(debug_context.llcontext,
&scc.output_filenames().with_extension("gcno")),
// path_to_mdstring(debug_context.llcontext,
// &scc.output_filenames().with_extension("gcda")),
cu_desc_metadata,
];
let gcov_metadata = llvm::LLVMMDNodeInContext(debug_context.llcontext,
gcov_cu_info.as_ptr(),
gcov_cu_info.len() as c_uint);
let llvm_gcov_ident = CString::new("llvm.gcov").unwrap();
llvm::LLVMAddNamedMetadataOperand(debug_context.llmod,
llvm_gcov_ident.as_ptr(),
gcov_metadata);
let llvm_gcov_ident = CString::new("llvm.gcov").unwrap();
llvm::LLVMAddNamedMetadataOperand(debug_context.llmod,
llvm_gcov_ident.as_ptr(),
gcov_metadata);
}
return unit_metadata;
};