@@ -436,6 +436,7 @@ pub fn create_bcx<'a, 'gctx>(
436
436
& units,
437
437
& scrape_units,
438
438
host_kind_requested. then_some ( explicit_host_kind) ,
439
+ & target_data,
439
440
) ;
440
441
441
442
let mut extra_compiler_args = HashMap :: new ( ) ;
@@ -575,6 +576,7 @@ fn rebuild_unit_graph_shared(
575
576
roots : & [ Unit ] ,
576
577
scrape_units : & [ Unit ] ,
577
578
to_host : Option < CompileKind > ,
579
+ target_data : & RustcTargetData < ' _ > ,
578
580
) -> ( Vec < Unit > , Vec < Unit > , UnitGraph ) {
579
581
let mut result = UnitGraph :: new ( ) ;
580
582
// Map of the old unit to the new unit, used to avoid recursing into units
@@ -591,6 +593,7 @@ fn rebuild_unit_graph_shared(
591
593
root,
592
594
false ,
593
595
to_host,
596
+ target_data,
594
597
)
595
598
} )
596
599
. collect ( ) ;
@@ -617,6 +620,7 @@ fn traverse_and_share(
617
620
unit : & Unit ,
618
621
unit_is_for_host : bool ,
619
622
to_host : Option < CompileKind > ,
623
+ target_data : & RustcTargetData < ' _ > ,
620
624
) -> Unit {
621
625
if let Some ( new_unit) = memo. get ( unit) {
622
626
// Already computed, no need to recompute.
@@ -634,6 +638,7 @@ fn traverse_and_share(
634
638
& dep. unit ,
635
639
dep. unit_for . is_for_host ( ) ,
636
640
to_host,
641
+ target_data,
637
642
) ;
638
643
new_dep_unit. hash ( & mut dep_hash) ;
639
644
UnitDep {
@@ -657,8 +662,13 @@ fn traverse_and_share(
657
662
_ => unit. kind ,
658
663
} ;
659
664
665
+ let is_target_windows_msvc = target_data
666
+ . short_name ( & unit. kind )
667
+ . ends_with ( "-pc-windows-msvc" ) ;
660
668
let mut profile = unit. profile . clone ( ) ;
661
- if profile. strip . is_deferred ( ) {
669
+ // For MSVC, rustc currently treats -Cstrip=debuginfo same as -Cstrip=symbols, which causes
670
+ // this optimization to also remove symbols and thus break backtraces.
671
+ if profile. strip . is_deferred ( ) && !is_target_windows_msvc {
662
672
// If strip was not manually set, and all dependencies of this unit together
663
673
// with this unit have debuginfo turned off, we enable debuginfo stripping.
664
674
// This will remove pre-existing debug symbols coming from the standard library.
0 commit comments