From 550107b44ccd86726a65e2c2022603230687469e Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Mon, 10 Nov 2025 09:43:44 -0800 Subject: [PATCH] Build with -Zannotate-moves by default (non-stage-0 only) Build rustc and tools with -Zannotate-moves by default, both to exercise the feature and because could be useful for doing performance measurement on rustc and its tools. This is only added for stage 1 and later. Stage 0 (the bootstrap compiler) doesn't yet support -Zannotate-moves. --- bootstrap.example.toml | 11 +++++++++++ src/bootstrap/src/core/builder/cargo.rs | 10 ++++++++++ src/bootstrap/src/core/config/config.rs | 6 ++++++ src/bootstrap/src/core/config/toml/rust.rs | 4 ++++ 4 files changed, 31 insertions(+) diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 0d0f5e405d1f4..40699bcc66fc7 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -828,6 +828,17 @@ # If an explicit setting is given, it will be used for all parts of the codebase. #rust.new-symbol-mangling = true|false (see comment) +# Enable move/copy annotations for profiler visibility. When enabled, compiler-generated +# move and copy operations will be annotated with debug info that makes them visible in +# profilers. This is helpful when profiling to see where expensive copies/moves occur. +# Defaults to true (enabled). +#rust.annotate-moves = true + +# Size limit in bytes for move/copy annotations. Only types at or above this size will +# be annotated. If not specified, uses the default limit (65 bytes). Only takes effect +# if annotate-moves is enabled. +#rust.annotate-moves-size-limit = 65 + # Select LTO mode that will be used for compiling rustc. By default, thin local LTO # (LTO within a single crate) is used (like for any Rust crate). You can also select # "thin" or "fat" to apply Thin/Fat LTO to the `rustc_driver` dylib, or "off" to disable diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index c2029f97391d4..16b1d33776803 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -654,6 +654,16 @@ impl Builder<'_> { rustflags.arg("-Csymbol-mangling-version=legacy"); } + // Enable move/copy annotations for profiler visibility if configured + // Skip stage 0 since the bootstrap compiler doesn't support this flag yet + if self.config.rust_annotate_moves.unwrap_or(true) && build_compiler_stage >= 1 { + if let Some(limit) = self.config.rust_annotate_moves_size_limit { + rustflags.arg(&format!("-Zannotate-moves={}", limit)); + } else { + rustflags.arg("-Zannotate-moves"); + } + } + // FIXME: the following components don't build with `-Zrandomize-layout` yet: // - rust-analyzer, due to the rowan crate // so we exclude an entire category of steps here due to lack of fine-grained control over diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 4b7ae6df360dc..d6b366474cc8e 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -216,6 +216,8 @@ pub struct Config { pub rust_thin_lto_import_instr_limit: Option, pub rust_randomize_layout: bool, pub rust_remap_debuginfo: bool, + pub rust_annotate_moves: Option, + pub rust_annotate_moves_size_limit: Option, pub rust_new_symbol_mangling: Option, pub rust_profile_use: Option, pub rust_profile_generate: Option, @@ -558,6 +560,8 @@ impl Config { llvm_libunwind: rust_llvm_libunwind, control_flow_guard: rust_control_flow_guard, ehcont_guard: rust_ehcont_guard, + annotate_moves: rust_annotate_moves, + annotate_moves_size_limit: rust_annotate_moves_size_limit, new_symbol_mangling: rust_new_symbol_mangling, profile_generate: rust_profile_generate, profile_use: rust_profile_use, @@ -1398,6 +1402,8 @@ impl Config { reproducible_artifacts: flags_reproducible_artifact, reuse: build_reuse.map(PathBuf::from), rust_analyzer_info, + rust_annotate_moves, + rust_annotate_moves_size_limit, rust_break_on_ice: rust_break_on_ice.unwrap_or(true), rust_codegen_backends: rust_codegen_backends .map(|backends| parse_codegen_backends(backends, "rust")) diff --git a/src/bootstrap/src/core/config/toml/rust.rs b/src/bootstrap/src/core/config/toml/rust.rs index cb48c7d9aadad..fa6934e9c9f48 100644 --- a/src/bootstrap/src/core/config/toml/rust.rs +++ b/src/bootstrap/src/core/config/toml/rust.rs @@ -59,6 +59,8 @@ define_config! { llvm_libunwind: Option = "llvm-libunwind", control_flow_guard: Option = "control-flow-guard", ehcont_guard: Option = "ehcont-guard", + annotate_moves: Option = "annotate-moves", + annotate_moves_size_limit: Option = "annotate-moves-size-limit", new_symbol_mangling: Option = "new-symbol-mangling", profile_generate: Option = "profile-generate", profile_use: Option = "profile-use", @@ -363,6 +365,8 @@ pub fn check_incompatible_options_for_ci_rustc( llvm_libunwind: _, control_flow_guard: _, ehcont_guard: _, + annotate_moves: _, + annotate_moves_size_limit: _, new_symbol_mangling: _, profile_generate: _, profile_use: _,