Skip to content

Commit 8a57e30

Browse files
committed
bootstrap: remap compiler vs non-compiler sources differently
- Map compiler sources (corresponding to `rustc-dev` dist component) with `/rustc-dev/{hash}`. - Map non-compiler sources (corresponding to `rust-src` dist component or other non-compiler sources) with `/rustc/{hash}`. This allows the compiler to have the possibility of opportunistically reverse the mapping. This is because - `rust-src` unpacks sources to a path like `$sysroot/lib/rustlib/src/rust`, whereas - `rustc-dev` unpacks sources to a path like `$sysroot/lib/rustlib/rustc-src/rust` (Notice the `src` vs `rustc-src` difference.)
1 parent 1bbd62e commit 8a57e30

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,12 +920,13 @@ impl Builder<'_> {
920920
hostflags.arg(format!("-Ctarget-feature={sign}crt-static"));
921921
}
922922

923-
if let Some(map_to) = self.build.debuginfo_map_to(GitRepo::Rustc) {
923+
if let Some(map_to) = self.build.debuginfo_map_to(GitRepo::Rustc, Some(mode)) {
924924
let map = format!("{}={}", self.build.src.display(), map_to);
925925
cargo.env("RUSTC_DEBUGINFO_MAP", map);
926926

927-
// `rustc` needs to know the virtual `/rustc/$hash` we're mapping to,
928-
// in order to opportunistically reverse it later.
927+
// `rustc` needs to know the virtual `/rustc/$hash` or `/rustc-dev/$hash` (depending on
928+
// non-compiler sources vs compiler sources) we're mapping to, in order to
929+
// opportunistically reverse it later.
929930
cargo.env("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR", map_to);
930931
}
931932

src/bootstrap/src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,15 +1194,27 @@ Executed at: {executed_at}"#,
11941194
})
11951195
}
11961196

1197-
fn debuginfo_map_to(&self, which: GitRepo) -> Option<String> {
1197+
fn debuginfo_map_to(&self, which: GitRepo, mode: Option<Mode>) -> Option<String> {
11981198
if !self.config.rust_remap_debuginfo {
11991199
return None;
12001200
}
12011201

12021202
match which {
12031203
GitRepo::Rustc => {
12041204
let sha = self.rust_sha().unwrap_or(&self.version);
1205-
Some(format!("/rustc/{sha}"))
1205+
1206+
match mode {
1207+
// For compiler sources, remap via `/rustc-dev/{sha}` to allow distinguishing
1208+
// between compiler sources vs library sources, since `rustc-dev` dist component
1209+
// places them under `$sysroot/lib/rustlib/rustc-src/rust` as opposed to
1210+
// `rust-src`'s `$sysroot/lib/rustlib/src/rust`.
1211+
//
1212+
// Keep this in sync with `rustc_metadata::rmeta::decoder`'s
1213+
// `try_to_translate_virtual_to_real`.
1214+
Some(Mode::Rustc) => Some(format!("/rustc-dev/{sha}")),
1215+
// For non-compiler sources, just use `/rustc/{sha}` remapping.
1216+
_ => Some(format!("/rustc/{sha}")),
1217+
}
12061218
}
12071219
GitRepo::Llvm => Some(String::from("/rustc/llvm")),
12081220
}
@@ -1269,7 +1281,7 @@ Executed at: {executed_at}"#,
12691281
base.push("-fno-omit-frame-pointer".into());
12701282
}
12711283

1272-
if let Some(map_to) = self.debuginfo_map_to(which) {
1284+
if let Some(map_to) = self.debuginfo_map_to(which, None) {
12731285
let map = format!("{}={}", self.src.display(), map_to);
12741286
let cc = self.cc(target);
12751287
if cc.ends_with("clang") || cc.ends_with("gcc") {

0 commit comments

Comments
 (0)