1
Fork 0

Add -Z simulate-remapped-rust-src-base option to simulate path virutalisation during bootstrapping

This commit is contained in:
Andy Wang 2021-05-01 12:28:45 +01:00
parent 5417b45c26
commit 0ac9ca4f88
No known key found for this signature in database
GPG key ID: 181B49F9F38F3374
4 changed files with 35 additions and 3 deletions

View file

@ -595,6 +595,7 @@ fn test_debugging_options_tracking_hash() {
tracked!(profile_emit, Some(PathBuf::from("abc")));
tracked!(relax_elf_relocations, Some(true));
tracked!(relro_level, Some(RelroLevel::Full));
tracked!(simulate_remapped_rust_src_base, Some(PathBuf::from("/rustc/abc")));
tracked!(report_delayed_bugs, true);
tracked!(sanitizer, SanitizerSet::ADDRESS);
tracked!(sanitizer_memory_track_origins, 2);

View file

@ -1707,6 +1707,31 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
..
} = source_file_to_import;
// If this file is under $sysroot/lib/rustlib/src/ but has not been remapped
// during rust bootstrapping by `remap-debuginfo = true`, and the user
// wish to simulate that behaviour by -Z simulate-remapped-rust-src-base,
// then we change `name` to a similar state as if the rust was bootstrapped
// with `remap-debuginfo = true`.
// This is useful for testing so that tests about the effects of
// `try_to_translate_virtual_to_real` don't have to worry about how the
// compiler is bootstrapped.
if let Some(virtual_dir) =
&sess.opts.debugging_opts.simulate_remapped_rust_src_base
{
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
if let rustc_span::FileName::Real(ref mut old_name) = name {
if let rustc_span::RealFileName::LocalPath(local) = old_name {
if let Ok(rest) = local.strip_prefix(real_dir) {
*old_name = rustc_span::RealFileName::Remapped {
local_path: None,
virtual_name: virtual_dir.join(rest),
};
}
}
}
}
}
// If this file's path has been remapped to `/rustc/$hash`,
// we might be able to reverse that (also see comments above,
// on `try_to_translate_virtual_to_real`).

View file

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

View file

@ -1,10 +1,13 @@
// ignore-windows
// compile-flags: -g -C no-prepopulate-passes --remap-path-prefix=/=/the/root/
// compile-flags: -g -C no-prepopulate-passes -Z simulate-remapped-rust-src-base=/rustc/xyz
// Here we check that imported code from std has their path remapped
// Here we check that importing std will not cause real path to std source files
// to leak. If rustc was compiled with remap-debuginfo = true, this should be
// true automatically. If paths to std library hasn't been remapped, we use the
// above simulate-remapped-rust-src-base option to do it temporarily
// CHECK: !DIFile(filename: "{{/the/root/.*/library/std/src/panic.rs}}"
// CHECK: !DIFile(filename: "{{/rustc/.*/library/std/src/panic.rs}}"
fn main() {
std::thread::spawn(|| {
println!("hello");