Skip to content

Commit 526c67f

Browse files
Rollup merge of rust-lang#131829 - Zalathar:goodbye-zprofile, r=chenyukang
Remove support for `-Zprofile` (gcov-style coverage instrumentation) Tracking issue: rust-lang#42524 MCP: rust-lang/compiler-team#798 --- This PR removes the unstable `-Zprofile` flag, which enables ”gcov-style” coverage instrumentation, along with its associated `-Zprofile-emit` configuration flag. (The profile flag predates and is almost entirely separate from the stable `-Cinstrument-coverage` flag.) Notably, the `-Zprofile` flag: - Is largely untested in-tree, having only one run-make test that does not check whether its output is correct or useful. - Has no known maintainer. - Has seen no push towards stabilization. - Has at least one severe regression reported in 2022 that apparently remains unaddressed. - rust-lang#100125 - Is confusingly named, since it appears to be more about coverage than performance profiling, and has nothing to do with PGO. - Is fundamentally limited by relying on counters auto-inserted by LLVM, with no knowledge of Rust beyond debuginfo.
2 parents 5ca0e9f + ce3e14a commit 526c67f

File tree

15 files changed

+10
-146
lines changed

15 files changed

+10
-146
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

-5
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,6 @@ fn probestack_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
232232
return None;
233233
}
234234

235-
// probestack doesn't play nice either with gcov profiling.
236-
if cx.sess().opts.unstable_opts.profile {
237-
return None;
238-
}
239-
240235
let attr_value = match cx.sess().target.stack_probes {
241236
StackProbeType::None => return None,
242237
// Request LLVM to generate the probes inline. If the given LLVM version does not support

compiler/rustc_codegen_llvm/src/back/write.rs

-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,6 @@ pub(crate) unsafe fn llvm_optimize(
591591
pgo_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
592592
config.instrument_coverage,
593593
instr_profile_output_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
594-
config.instrument_gcov,
595594
pgo_sample_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
596595
config.debug_info_for_profiling,
597596
llvm_selfprofiler,

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{iter, ptr};
77
use libc::{c_char, c_longlong, c_uint};
88
use rustc_codegen_ssa::debuginfo::type_names::{VTableNameKind, cpp_like_debuginfo};
99
use rustc_codegen_ssa::traits::*;
10-
use rustc_fs_util::path_to_c_string;
1110
use rustc_hir::def::{CtorKind, DefKind};
1211
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1312
use rustc_middle::bug;
@@ -979,33 +978,8 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
979978
debug_name_table_kind,
980979
);
981980

982-
if tcx.sess.opts.unstable_opts.profile {
983-
let default_gcda_path = &output_filenames.with_extension("gcda");
984-
let gcda_path =
985-
tcx.sess.opts.unstable_opts.profile_emit.as_ref().unwrap_or(default_gcda_path);
986-
987-
let gcov_cu_info = [
988-
path_to_mdstring(debug_context.llcontext, &output_filenames.with_extension("gcno")),
989-
path_to_mdstring(debug_context.llcontext, gcda_path),
990-
unit_metadata,
991-
];
992-
let gcov_metadata = llvm::LLVMMDNodeInContext2(
993-
debug_context.llcontext,
994-
gcov_cu_info.as_ptr(),
995-
gcov_cu_info.len(),
996-
);
997-
let val = llvm::LLVMMetadataAsValue(debug_context.llcontext, gcov_metadata);
998-
999-
llvm::LLVMAddNamedMetadataOperand(debug_context.llmod, c"llvm.gcov".as_ptr(), val);
1000-
}
1001-
1002981
return unit_metadata;
1003982
};
1004-
1005-
fn path_to_mdstring<'ll>(llcx: &'ll llvm::Context, path: &Path) -> &'ll llvm::Metadata {
1006-
let path_str = path_to_c_string(path);
1007-
unsafe { llvm::LLVMMDStringInContext2(llcx, path_str.as_ptr(), path_str.as_bytes().len()) }
1008-
}
1009983
}
1010984

1011985
/// Creates a `DW_TAG_member` entry inside the DIE represented by the given `type_di_node`.

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const DW_TAG_arg_variable: c_uint = 0x101;
5555

5656
/// A context object for maintaining all state needed by the debuginfo module.
5757
pub(crate) struct CodegenUnitDebugContext<'ll, 'tcx> {
58-
llcontext: &'ll llvm::Context,
5958
llmod: &'ll llvm::Module,
6059
builder: &'ll mut DIBuilder<'ll>,
6160
created_files: RefCell<UnordMap<Option<(StableSourceFileId, SourceFileHash)>, &'ll DIFile>>,
@@ -78,9 +77,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
7877
debug!("CodegenUnitDebugContext::new");
7978
let builder = unsafe { llvm::LLVMRustDIBuilderCreate(llmod) };
8079
// DIBuilder inherits context from the module, so we'd better use the same one
81-
let llcontext = unsafe { llvm::LLVMGetModuleContext(llmod) };
8280
CodegenUnitDebugContext {
83-
llcontext,
8481
llmod,
8582
builder,
8683
created_files: Default::default(),

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,6 @@ unsafe extern "C" {
22692269
PGOUsePath: *const c_char,
22702270
InstrumentCoverage: bool,
22712271
InstrProfileOutput: *const c_char,
2272-
InstrumentGCOV: bool,
22732272
PGOSampleUsePath: *const c_char,
22742273
DebugInfoForProfiling: bool,
22752274
llvm_selfprofiler: *mut c_void,

compiler/rustc_codegen_ssa/src/back/write.rs

+4-21
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub struct ModuleConfig {
9090
pub pgo_sample_use: Option<PathBuf>,
9191
pub debug_info_for_profiling: bool,
9292
pub instrument_coverage: bool,
93-
pub instrument_gcov: bool,
9493

9594
pub sanitizer: SanitizerSet,
9695
pub sanitizer_recover: SanitizerSet,
@@ -123,12 +122,7 @@ pub struct ModuleConfig {
123122
}
124123

125124
impl ModuleConfig {
126-
fn new(
127-
kind: ModuleKind,
128-
tcx: TyCtxt<'_>,
129-
no_builtins: bool,
130-
is_compiler_builtins: bool,
131-
) -> ModuleConfig {
125+
fn new(kind: ModuleKind, tcx: TyCtxt<'_>, no_builtins: bool) -> ModuleConfig {
132126
// If it's a regular module, use `$regular`, otherwise use `$other`.
133127
// `$regular` and `$other` are evaluated lazily.
134128
macro_rules! if_regular {
@@ -189,13 +183,6 @@ impl ModuleConfig {
189183
pgo_sample_use: if_regular!(sess.opts.unstable_opts.profile_sample_use.clone(), None),
190184
debug_info_for_profiling: sess.opts.unstable_opts.debug_info_for_profiling,
191185
instrument_coverage: if_regular!(sess.instrument_coverage(), false),
192-
instrument_gcov: if_regular!(
193-
// compiler_builtins overrides the codegen-units settings,
194-
// which is incompatible with -Zprofile which requires that
195-
// only a single codegen unit is used per crate.
196-
sess.opts.unstable_opts.profile && !is_compiler_builtins,
197-
false
198-
),
199186

200187
sanitizer: if_regular!(sess.opts.unstable_opts.sanitizer, SanitizerSet::empty()),
201188
sanitizer_dataflow_abilist: if_regular!(
@@ -473,16 +460,12 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
473460

474461
let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
475462
let no_builtins = attr::contains_name(crate_attrs, sym::no_builtins);
476-
let is_compiler_builtins = attr::contains_name(crate_attrs, sym::compiler_builtins);
477463

478464
let crate_info = CrateInfo::new(tcx, target_cpu);
479465

480-
let regular_config =
481-
ModuleConfig::new(ModuleKind::Regular, tcx, no_builtins, is_compiler_builtins);
482-
let metadata_config =
483-
ModuleConfig::new(ModuleKind::Metadata, tcx, no_builtins, is_compiler_builtins);
484-
let allocator_config =
485-
ModuleConfig::new(ModuleKind::Allocator, tcx, no_builtins, is_compiler_builtins);
466+
let regular_config = ModuleConfig::new(ModuleKind::Regular, tcx, no_builtins);
467+
let metadata_config = ModuleConfig::new(ModuleKind::Metadata, tcx, no_builtins);
468+
let allocator_config = ModuleConfig::new(ModuleKind::Allocator, tcx, no_builtins);
486469

487470
let (shared_emitter, shared_emitter_main) = SharedEmitter::new();
488471
let (codegen_worker_send, codegen_worker_receive) = channel();

compiler/rustc_interface/src/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,6 @@ fn test_unstable_options_tracking_hash() {
832832
tracked!(polonius, Polonius::Legacy);
833833
tracked!(precise_enum_drop_elaboration, false);
834834
tracked!(print_fuel, Some("abc".to_string()));
835-
tracked!(profile, true);
836-
tracked!(profile_emit, Some(PathBuf::from("abc")));
837835
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
838836
tracked!(profiler_runtime, "abc".to_string());
839837
tracked!(regparm, Some(3));

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+2-11
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#if LLVM_VERSION_GE(19, 0)
4343
#include "llvm/Support/PGOOptions.h"
4444
#endif
45-
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
4645
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
4746
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
4847
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
@@ -714,9 +713,8 @@ extern "C" LLVMRustResult LLVMRustOptimize(
714713
bool SLPVectorize, bool LoopVectorize, bool DisableSimplifyLibCalls,
715714
bool EmitLifetimeMarkers, LLVMRustSanitizerOptions *SanitizerOptions,
716715
const char *PGOGenPath, const char *PGOUsePath, bool InstrumentCoverage,
717-
const char *InstrProfileOutput, bool InstrumentGCOV,
718-
const char *PGOSampleUsePath, bool DebugInfoForProfiling,
719-
void *LlvmSelfProfiler,
716+
const char *InstrProfileOutput, const char *PGOSampleUsePath,
717+
bool DebugInfoForProfiling, void *LlvmSelfProfiler,
720718
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
721719
LLVMRustSelfProfileAfterPassCallback AfterPassCallback,
722720
const char *ExtraPasses, size_t ExtraPassesLen, const char *LLVMPlugins,
@@ -847,13 +845,6 @@ extern "C" LLVMRustResult LLVMRustOptimize(
847845
});
848846
}
849847

850-
if (InstrumentGCOV) {
851-
PipelineStartEPCallbacks.push_back(
852-
[](ModulePassManager &MPM, OptimizationLevel Level) {
853-
MPM.addPass(GCOVProfilerPass(GCOVOptions::getDefault()));
854-
});
855-
}
856-
857848
if (InstrumentCoverage) {
858849
PipelineStartEPCallbacks.push_back(
859850
[InstrProfileOutput](ModulePassManager &MPM, OptimizationLevel Level) {

compiler/rustc_metadata/src/creader.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
778778

779779
fn inject_profiler_runtime(&mut self, krate: &ast::Crate) {
780780
if self.sess.opts.unstable_opts.no_profiler_runtime
781-
|| !(self.sess.instrument_coverage()
782-
|| self.sess.opts.unstable_opts.profile
783-
|| self.sess.opts.cg.profile_generate.enabled())
781+
|| !(self.sess.instrument_coverage() || self.sess.opts.cg.profile_generate.enabled())
784782
{
785783
return;
786784
}

compiler/rustc_session/src/config.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
24532453
let output_types = parse_output_types(early_dcx, &unstable_opts, matches);
24542454

24552455
let mut cg = CodegenOptions::build(early_dcx, matches);
2456-
let (disable_local_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto(
2456+
let (disable_local_thinlto, codegen_units) = should_override_cgus_and_disable_thinlto(
24572457
early_dcx,
24582458
&output_types,
24592459
matches,
@@ -2476,18 +2476,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
24762476

24772477
let assert_incr_state = parse_assert_incr_state(early_dcx, &unstable_opts.assert_incr_state);
24782478

2479-
if unstable_opts.profile && incremental.is_some() {
2480-
early_dcx.early_fatal("can't instrument with gcov profiling when compiling incrementally");
2481-
}
2482-
if unstable_opts.profile {
2483-
match codegen_units {
2484-
Some(1) => {}
2485-
None => codegen_units = Some(1),
2486-
Some(_) => early_dcx
2487-
.early_fatal("can't instrument with gcov profiling with multiple codegen units"),
2488-
}
2489-
}
2490-
24912479
if cg.profile_generate.enabled() && cg.profile_use.is_some() {
24922480
early_dcx.early_fatal("options `-C profile-generate` and `-C profile-use` are exclusive");
24932481
}

compiler/rustc_session/src/options.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1985,13 +1985,8 @@ options! {
19851985
proc_macro_execution_strategy: ProcMacroExecutionStrategy = (ProcMacroExecutionStrategy::SameThread,
19861986
parse_proc_macro_execution_strategy, [UNTRACKED],
19871987
"how to run proc-macro code (default: same-thread)"),
1988-
profile: bool = (false, parse_bool, [TRACKED],
1989-
"insert profiling code (default: no)"),
19901988
profile_closures: bool = (false, parse_no_flag, [UNTRACKED],
19911989
"profile size of closures"),
1992-
profile_emit: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1993-
"file path to emit profiling data at runtime when using 'profile' \
1994-
(default based on relative source path)"),
19951990
profile_sample_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
19961991
"use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"),
19971992
profiler_runtime: String = (String::from("profiler_builtins"), parse_string, [TRACKED],

src/doc/rustc/src/instrument-coverage.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
## Introduction
44

5-
The Rust compiler includes two code coverage implementations:
6-
7-
- A GCC-compatible, gcov-based coverage implementation, enabled with `-Z profile`, which derives coverage data based on DebugInfo.
8-
- A source-based code coverage implementation, enabled with `-C instrument-coverage`, which uses LLVM's native, efficient coverage instrumentation to generate very precise coverage data.
9-
10-
This document describes how to enable and use the LLVM instrumentation-based coverage, via the `-C instrument-coverage` compiler flag.
5+
This document describes how to enable and use LLVM instrumentation-based coverage,
6+
via the `-C instrument-coverage` compiler flag.
117

128
## How it works
139

src/doc/unstable-book/src/compiler-flags/profile.md

-27
This file was deleted.

tests/run-make/profile/rmake.rs

-21
This file was deleted.

tests/run-make/profile/test.rs

-1
This file was deleted.

0 commit comments

Comments
 (0)