diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index ff9607e715ec2..041a1ebfd8b2c 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -152,7 +152,7 @@ pub(crate) fn frame_pointer_type_attr<'ll>( let opts = &sess.opts; // "mcount" function relies on stack pointer. // See . - if opts.unstable_opts.instrument_mcount { + if opts.cg.instrument_mcount { fp.ratchet(FramePointer::Always); } fp.ratchet(opts.cg.force_frame_pointers); @@ -180,7 +180,7 @@ fn instrument_function_attr<'ll>( sess: &Session, ) -> SmallVec<[&'ll Attribute; 4]> { let mut attrs = SmallVec::new(); - if sess.opts.unstable_opts.instrument_mcount { + if sess.opts.cg.instrument_mcount { // Similar to `clang -pg` behavior. Handled by the // `post-inline-ee-instrument` LLVM pass. diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 6c08b37dec083..ec8ef039f8f74 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -620,6 +620,7 @@ fn test_codegen_options_tracking_hash() { tracked!(force_frame_pointers, FramePointer::Always); tracked!(force_unwind_tables, Some(true)); tracked!(instrument_coverage, InstrumentCoverage::Yes); + tracked!(instrument_mcount, true); tracked!(jump_tables, false); tracked!(link_dead_code, Some(true)); tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto); @@ -813,7 +814,6 @@ fn test_unstable_options_tracking_hash() { tracked!(inline_mir, Some(true)); tracked!(inline_mir_hint_threshold, Some(123)); tracked!(inline_mir_threshold, Some(123)); - tracked!(instrument_mcount, true); tracked!(instrument_xray, Some(InstrumentXRay::default())); tracked!(link_directives, false); tracked!(link_only, true); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index c9d73adf31d49..bd8b6aff1860e 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2093,6 +2093,8 @@ options! { "instrument the generated code to support LLVM source-based code coverage reports \ (note, the compiler build config must include `profiler = true`); \ implies `-C symbol-mangling-version=v0`"), + instrument_mcount: bool = (false, parse_bool, [TRACKED], + "insert function instrument code for mcount-based tracing (default: no)"), jump_tables: bool = (true, parse_bool, [TRACKED], "allow jump table and lookup table generation from switch case lowering (default: yes)"), link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED], @@ -2385,8 +2387,6 @@ options! { "a default MIR inlining threshold (default: 50)"), input_stats: bool = (false, parse_bool, [UNTRACKED], "print some statistics about AST and HIR (default: no)"), - instrument_mcount: bool = (false, parse_bool, [TRACKED], - "insert function instrument code for mcount-based tracing (default: no)"), instrument_xray: Option = (None, parse_instrument_xray, [TRACKED], "insert function instrument code for XRay-based tracing (default: no) Optional extra settings: diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index f0f991ed0c909..e9ebb163c88ff 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -209,6 +209,12 @@ Note that while the `-C instrument-coverage` option is stable, the profile data format produced by the resulting instrumentation may change, and may not work with coverage tools other than those built and shipped with the compiler. +## instrument-mcount + +This option inserts an mcount profiling call into each function prologue within +the crate being compiled. The instrumentation is compatible with gprof and +similiar tools. + ## jump-tables This option is used to allow or prevent the LLVM codegen backend from creating diff --git a/tests/assembly-llvm/x86_64-mcount.rs b/tests/assembly-llvm/x86_64-mcount.rs index 0428272cfc598..6fb1d3d1cf5b5 100644 --- a/tests/assembly-llvm/x86_64-mcount.rs +++ b/tests/assembly-llvm/x86_64-mcount.rs @@ -1,5 +1,5 @@ //@ assembly-output: emit-asm -//@ compile-flags: -Zinstrument-mcount=y -Cllvm-args=-x86-asm-syntax=intel +//@ compile-flags: -Cinstrument-mcount=y -Cllvm-args=-x86-asm-syntax=intel //@ revisions: x86_64-linux //@[x86_64-linux] compile-flags: --target=x86_64-unknown-linux-gnu diff --git a/tests/codegen-llvm/instrument-mcount.rs b/tests/codegen-llvm/instrument-mcount.rs index 8c97535d4a82c..7ec7df6b5cf28 100644 --- a/tests/codegen-llvm/instrument-mcount.rs +++ b/tests/codegen-llvm/instrument-mcount.rs @@ -1,5 +1,5 @@ // -//@ compile-flags: -Z instrument-mcount -Copt-level=0 +//@ compile-flags: -C instrument-mcount=yes -Copt-level=0 #![crate_type = "lib"]