From 09e60434830d4b6387df03ee54cfb5207a06a1ff Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:11:19 +0100 Subject: [PATCH] Add `rust.frame-pointers` config option This is very helpful for profiling. I've hacked this in many times, so let's add it properly. --- config.example.toml | 4 ++++ src/bootstrap/defaults/config.codegen.toml | 3 +++ src/bootstrap/defaults/config.compiler.toml | 3 +++ src/bootstrap/src/core/builder.rs | 4 ++++ src/bootstrap/src/core/config/config.rs | 4 ++++ src/bootstrap/src/utils/change_tracker.rs | 5 +++++ 6 files changed, 23 insertions(+) diff --git a/config.example.toml b/config.example.toml index 975fcd71fc94d..cef33a7905a3b 100644 --- a/config.example.toml +++ b/config.example.toml @@ -612,6 +612,10 @@ # Indicates whether symbols should be stripped using `-Cstrip=symbols`. #strip = false +# Forces frame pointers to be used with `-Cforce-frame-pointers`. +# This can be helpful for profiling at a small performance cost. +# frame-pointers = false + # Indicates whether stack protectors should be used # via the unstable option `-Zstack-protector`. # diff --git a/src/bootstrap/defaults/config.codegen.toml b/src/bootstrap/defaults/config.codegen.toml index 7c33ce958c929..cf336d7a63639 100644 --- a/src/bootstrap/defaults/config.codegen.toml +++ b/src/bootstrap/defaults/config.codegen.toml @@ -23,3 +23,6 @@ incremental = true backtrace-on-ice = true # Make the compiler and standard library faster to build, at the expense of a ~20% runtime slowdown. lto = "off" +# Forces frame pointers to be used with `-Cforce-frame-pointers`. +# This can be helpful for profiling at a small performance cost. +frame-pointers = true diff --git a/src/bootstrap/defaults/config.compiler.toml b/src/bootstrap/defaults/config.compiler.toml index b27b524b873b7..5c2d476d98e05 100644 --- a/src/bootstrap/defaults/config.compiler.toml +++ b/src/bootstrap/defaults/config.compiler.toml @@ -14,6 +14,9 @@ incremental = true backtrace-on-ice = true # Make the compiler and standard library faster to build, at the expense of a ~20% runtime slowdown. lto = "off" +# Forces frame pointers to be used with `-Cforce-frame-pointers`. +# This can be helpful for profiling at a small performance cost. +frame-pointers = true [llvm] # Will download LLVM from CI if available on your platform. diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 2c4013d78bf68..d993e4c44d41b 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -1870,6 +1870,10 @@ impl<'a> Builder<'a> { rustflags.arg("-Wrustc::internal"); } + if self.config.rust_frame_pointers { + rustflags.arg("-Cforce-frame-pointers=true"); + } + // If Control Flow Guard is enabled, pass the `control-flow-guard` flag to rustc // when compiling the standard library, since this might be linked into the final outputs // produced by rustc. Since this mitigation is only available on Windows, only enable it diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 05b9c73401814..1605776f77277 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -256,6 +256,7 @@ pub struct Config { pub rust_split_debuginfo: SplitDebuginfo, pub rust_rpath: bool, pub rust_strip: bool, + pub rust_frame_pointers: bool, pub rust_stack_protector: Option, pub rustc_parallel: bool, pub rustc_default_linker: Option, @@ -1083,6 +1084,7 @@ define_config! { musl_root: Option = "musl-root", rpath: Option = "rpath", strip: Option = "strip", + frame_pointers: Option = "frame-pointers", stack_protector: Option = "stack-protector", verbose_tests: Option = "verbose-tests", optimize_tests: Option = "optimize-tests", @@ -1561,6 +1563,7 @@ impl Config { download_rustc, lto, validate_mir_opts, + frame_pointers, stack_protector, strip, lld_mode, @@ -1609,6 +1612,7 @@ impl Config { set(&mut config.codegen_tests, codegen_tests); set(&mut config.rust_rpath, rpath); set(&mut config.rust_strip, strip); + set(&mut config.rust_frame_pointers, frame_pointers); config.rust_stack_protector = stack_protector; set(&mut config.jemalloc, jemalloc); set(&mut config.test_compare_mode, test_compare_mode); diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index ec62f9f1f8c1a..1625047d3e103 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -119,4 +119,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Info, summary: "New option `target..codegen-backends` added to config.toml.", }, + ChangeInfo { + change_id: 121203, + severity: ChangeSeverity::Info, + summary: "A new `rust.frame-pointers` option has been introduced and made the default in the compiler and codegen profiles.", + }, ];