]> git.lizzy.rs Git - rust.git/commitdiff
Add llvm.gcov metadata only if profiler is enabled
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Sun, 4 Jun 2017 16:50:25 +0000 (17:50 +0100)
committerMarco Castelluccio <mcastelluccio@mozilla.com>
Sun, 4 Jun 2017 16:50:25 +0000 (17:50 +0100)
src/librustc_trans/debuginfo/metadata.rs

index d9b99e0eb6831f932ecdb1f796e611e0b31703b6..32fd2bac85f4c57603f127a916a03d642bd968c1 100644 (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);
-
-        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);
+        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 llvm_gcov_ident = CString::new("llvm.gcov").unwrap();
+            llvm::LLVMAddNamedMetadataOperand(debug_context.llmod,
+                                              llvm_gcov_ident.as_ptr(),
+                                              gcov_metadata);
+        }
 
         return unit_metadata;
     };