Skip to content

Commit

Permalink
Add -Z simulate-remapped-rust-src-base option to simulate path viruta…
Browse files Browse the repository at this point in the history
…lisation during bootstrapping
  • Loading branch information
cbeuw committed May 5, 2021
1 parent 5417b45 commit 0ac9ca4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
9 changes: 6 additions & 3 deletions src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down

0 comments on commit 0ac9ca4

Please sign in to comment.