Skip to content

Commit 0ac9ca4

Browse files
committed
Add -Z simulate-remapped-rust-src-base option to simulate path virutalisation during bootstrapping
1 parent 5417b45 commit 0ac9ca4

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ fn test_debugging_options_tracking_hash() {
595595
tracked!(profile_emit, Some(PathBuf::from("abc")));
596596
tracked!(relax_elf_relocations, Some(true));
597597
tracked!(relro_level, Some(RelroLevel::Full));
598+
tracked!(simulate_remapped_rust_src_base, Some(PathBuf::from("/rustc/abc")));
598599
tracked!(report_delayed_bugs, true);
599600
tracked!(sanitizer, SanitizerSet::ADDRESS);
600601
tracked!(sanitizer_memory_track_origins, 2);

compiler/rustc_metadata/src/rmeta/decoder.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,31 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17071707
..
17081708
} = source_file_to_import;
17091709

1710+
// If this file is under $sysroot/lib/rustlib/src/ but has not been remapped
1711+
// during rust bootstrapping by `remap-debuginfo = true`, and the user
1712+
// wish to simulate that behaviour by -Z simulate-remapped-rust-src-base,
1713+
// then we change `name` to a similar state as if the rust was bootstrapped
1714+
// with `remap-debuginfo = true`.
1715+
// This is useful for testing so that tests about the effects of
1716+
// `try_to_translate_virtual_to_real` don't have to worry about how the
1717+
// compiler is bootstrapped.
1718+
if let Some(virtual_dir) =
1719+
&sess.opts.debugging_opts.simulate_remapped_rust_src_base
1720+
{
1721+
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
1722+
if let rustc_span::FileName::Real(ref mut old_name) = name {
1723+
if let rustc_span::RealFileName::LocalPath(local) = old_name {
1724+
if let Ok(rest) = local.strip_prefix(real_dir) {
1725+
*old_name = rustc_span::RealFileName::Remapped {
1726+
local_path: None,
1727+
virtual_name: virtual_dir.join(rest),
1728+
};
1729+
}
1730+
}
1731+
}
1732+
}
1733+
}
1734+
17101735
// If this file's path has been remapped to `/rustc/$hash`,
17111736
// we might be able to reverse that (also see comments above,
17121737
// on `try_to_translate_virtual_to_real`).

compiler/rustc_session/src/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11611161
"whether ELF relocations can be relaxed"),
11621162
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
11631163
"choose which RELRO level to use"),
1164+
simulate_remapped_rust_src_base: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1165+
"simulate the effect of remap-debuginfo = true at bootstrapping by remapping path \
1166+
to rust's source base directory. only meant for testing purposes"),
11641167
report_delayed_bugs: bool = (false, parse_bool, [TRACKED],
11651168
"immediately print bugs registered with `delay_span_bug` (default: no)"),
11661169
sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],

src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// ignore-windows
22

3-
// compile-flags: -g -C no-prepopulate-passes --remap-path-prefix=/=/the/root/
3+
// compile-flags: -g -C no-prepopulate-passes -Z simulate-remapped-rust-src-base=/rustc/xyz
44

5-
// Here we check that imported code from std has their path remapped
5+
// Here we check that importing std will not cause real path to std source files
6+
// to leak. If rustc was compiled with remap-debuginfo = true, this should be
7+
// true automatically. If paths to std library hasn't been remapped, we use the
8+
// above simulate-remapped-rust-src-base option to do it temporarily
69

7-
// CHECK: !DIFile(filename: "{{/the/root/.*/library/std/src/panic.rs}}"
10+
// CHECK: !DIFile(filename: "{{/rustc/.*/library/std/src/panic.rs}}"
811
fn main() {
912
std::thread::spawn(|| {
1013
println!("hello");

0 commit comments

Comments
 (0)