@@ -181,28 +181,31 @@ fn main() {
181181 cmd. arg ( "-C" ) . arg ( format ! ( "debug-assertions={}" , debug_assertions) ) ;
182182 }
183183
184- // Build `compiler_builtins` with `-Z emit-stack-sizes` to add stack usage information.
184+ // Build all crates in the `std` facade with `-Z emit-stack-sizes` to add stack usage
185+ // information.
185186 //
186- // When you use this flag with Cargo you get stack usage information on all crates compiled
187- // from source, and when you are using LTO you also get information on pre-compiled crates
188- // like `core` and `std`. However, there's an exception: `compiler_builtins`. This crate
189- // is special and doesn't participate in LTO because it's always linked as a separate object
190- // file. Due to this it's impossible to get information about this crate using `RUSTFLAGS`
191- // + Cargo, or `cargo rustc`.
187+ // When you use this `-Z` flag with Cargo you get stack usage information on all crates
188+ // compiled from source, and when you are using LTO you also get information on pre-compiled
189+ // crates like `core` and `std`, even if they were not compiled with `-Z emit-stack-sizes`.
190+ // However, there's an exception: `compiler_builtins`. This crate is special and doesn't
191+ // participate in LTO because it's always linked as a separate object file. For this reason
192+ // it's impossible to get stack usage information about `compiler-builtins` using
193+ // `RUSTFLAGS` + Cargo, or `cargo rustc`.
192194 //
193- // To make the stack usage information of this crate available to Cargo based stack usage
194- // analysis tools we compile `compiler_builtins` with the `-Z emit-stack-sizes` flag. The
195- // flag is known to currently work with targets that produce ELF files so we limit the use
196- // of the flag to those targets.
195+ // To make the stack usage information of all crates under the `std` facade available to
196+ // Cargo based stack usage analysis tools, in both LTO and non-LTO mode, we compile them
197+ // with the `-Z emit-stack-sizes` flag. The `RUSTC_EMIT_STACK_SIZES` var helps us apply this
198+ // flag only to the crates in the `std` facade. The `-Z` flag is known to currently work
199+ // with targets that produce ELF files so we limit its use flag to those targets.
197200 //
198201 // NOTE(japaric) if this ever causes problem with an LLVM upgrade or any PR feel free to
199202 // remove it or comment it out
200- if crate_name == "compiler_builtins"
203+ if env :: var_os ( "RUSTC_EMIT_STACK_SIZES" ) . is_some ( )
201204 && ( target. contains ( "-linux-" )
202205 || target. contains ( "-none-eabi" )
203206 || target. ends_with ( "-none-elf" ) )
204207 {
205- cmd. arg ( "-Z" ) . arg ( "emit -stack-sizes") ;
208+ cmd. arg ( "-Zemit -stack-sizes" ) ;
206209 }
207210
208211 if let Ok ( s) = env:: var ( "RUSTC_CODEGEN_UNITS" ) {
0 commit comments