Skip to content

Commit

Permalink
Do not strip debuginfo by default for MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Mar 23, 2024
1 parent 7ff7e34 commit de87e7c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ pub fn create_bcx<'a, 'gctx>(
&units,
&scrape_units,
host_kind_requested.then_some(explicit_host_kind),
&target_data,
);

let mut extra_compiler_args = HashMap::new();
Expand Down Expand Up @@ -575,6 +576,7 @@ fn rebuild_unit_graph_shared(
roots: &[Unit],
scrape_units: &[Unit],
to_host: Option<CompileKind>,
target_data: &RustcTargetData<'_>,
) -> (Vec<Unit>, Vec<Unit>, UnitGraph) {
let mut result = UnitGraph::new();
// Map of the old unit to the new unit, used to avoid recursing into units
Expand All @@ -591,6 +593,7 @@ fn rebuild_unit_graph_shared(
root,
false,
to_host,
target_data,
)
})
.collect();
Expand All @@ -617,6 +620,7 @@ fn traverse_and_share(
unit: &Unit,
unit_is_for_host: bool,
to_host: Option<CompileKind>,
target_data: &RustcTargetData<'_>,
) -> Unit {
if let Some(new_unit) = memo.get(unit) {
// Already computed, no need to recompute.
Expand All @@ -634,6 +638,7 @@ fn traverse_and_share(
&dep.unit,
dep.unit_for.is_for_host(),
to_host,
target_data,
);
new_dep_unit.hash(&mut dep_hash);
UnitDep {
Expand All @@ -657,8 +662,13 @@ fn traverse_and_share(
_ => unit.kind,
};

let is_target_windows_msvc = target_data
.short_name(&unit.kind)
.ends_with("-pc-windows-msvc");
let mut profile = unit.profile.clone();
if profile.strip.is_deferred() {
// For MSVC, rustc currently treats -Cstrip=debuginfo same as -Cstrip=symbols, which causes
// this optimization to also remove symbols and thus break backtraces.
if profile.strip.is_deferred() && !is_target_windows_msvc {
// If strip was not manually set, and all dependencies of this unit together
// with this unit have debuginfo turned off, we enable debuginfo stripping.
// This will remove pre-existing debug symbols coming from the standard library.
Expand Down

0 comments on commit de87e7c

Please sign in to comment.