From 65520ec802f77ab191423f3a1507d6c0be7cfb9c Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 3 Apr 2021 20:44:18 +0100 Subject: Add test for --remap-path-prefix on std imports --- src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs (limited to 'src/test/codegen') diff --git a/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs b/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs new file mode 100644 index 00000000000..56c695d4ded --- /dev/null +++ b/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs @@ -0,0 +1,12 @@ +// ignore-windows + +// compile-flags: -g -C no-prepopulate-passes --remap-path-prefix=/=/the/root/ + +// Here we check that imported code from std has their path remapped + +// CHECK: !DIFile(filename: "{{/the/root/.*/library/std/src/panic.rs}}" +fn main() { + std::thread::spawn(|| { + println!("hello"); + }); +} -- cgit 1.4.1-3-g733a5 From 0ac9ca4f88c03e6fc507ab8937573dca1ccfd2ed Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 1 May 2021 12:28:45 +0100 Subject: Add -Z simulate-remapped-rust-src-base option to simulate path virutalisation during bootstrapping --- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_metadata/src/rmeta/decoder.rs | 25 ++++++++++++++++++++++ compiler/rustc_session/src/options.rs | 3 +++ .../remap_path_prefix/issue-73167-remap-std.rs | 9 +++++--- 4 files changed, 35 insertions(+), 3 deletions(-) (limited to 'src/test/codegen') diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index d8c1a7a2682..33723e0b51e 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -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); diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 4cb90d5a6d6..493c9dc9563 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -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`). diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 1c2a7f7716d..3d069aa92e7 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1161,6 +1161,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "whether ELF relocations can be relaxed"), relro_level: Option = (None, parse_relro_level, [TRACKED], "choose which RELRO level to use"), + simulate_remapped_rust_src_base: Option = (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], diff --git a/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs b/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs index 56c695d4ded..b66abc6bedf 100644 --- a/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs +++ b/src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs @@ -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"); -- cgit 1.4.1-3-g733a5