about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2024-02-16 22:11:19 +0100
committerNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2024-02-18 22:23:09 +0100
commit09e60434830d4b6387df03ee54cfb5207a06a1ff (patch)
tree37233abd73fb29fa8b988677d448c4b4f744cb5a
parent8a497723e311a62fccb1f0bf40e79c6519744a12 (diff)
downloadrust-09e60434830d4b6387df03ee54cfb5207a06a1ff.tar.gz
rust-09e60434830d4b6387df03ee54cfb5207a06a1ff.zip
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.
-rw-r--r--config.example.toml4
-rw-r--r--src/bootstrap/defaults/config.codegen.toml3
-rw-r--r--src/bootstrap/defaults/config.compiler.toml3
-rw-r--r--src/bootstrap/src/core/builder.rs4
-rw-r--r--src/bootstrap/src/core/config/config.rs4
-rw-r--r--src/bootstrap/src/utils/change_tracker.rs5
6 files changed, 23 insertions, 0 deletions
diff --git a/config.example.toml b/config.example.toml
index 975fcd71fc9..cef33a7905a 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 7c33ce958c9..cf336d7a636 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 b27b524b873..5c2d476d98e 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 2c4013d78bf..d993e4c44d4 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 05b9c734018..1605776f772 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<String>,
     pub rustc_parallel: bool,
     pub rustc_default_linker: Option<String>,
@@ -1083,6 +1084,7 @@ define_config! {
         musl_root: Option<String> = "musl-root",
         rpath: Option<bool> = "rpath",
         strip: Option<bool> = "strip",
+        frame_pointers: Option<bool> = "frame-pointers",
         stack_protector: Option<String> = "stack-protector",
         verbose_tests: Option<bool> = "verbose-tests",
         optimize_tests: Option<bool> = "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 ec62f9f1f8c..1625047d3e1 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.<triple>.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.",
+    },
 ];