diff options
| author | Andy Wang <cbeuw.andy@gmail.com> | 2021-05-01 12:28:45 +0100 |
|---|---|---|
| committer | Andy Wang <cbeuw.andy@gmail.com> | 2021-05-05 15:31:32 +0100 |
| commit | 0ac9ca4f88c03e6fc507ab8937573dca1ccfd2ed (patch) | |
| tree | 3ea40c134bb503668dc11c20c687dc76a7b81316 | |
| parent | 5417b45c2676dcd396f007bd89ed0cd55d085768 (diff) | |
| download | rust-0ac9ca4f88c03e6fc507ab8937573dca1ccfd2ed.tar.gz rust-0ac9ca4f88c03e6fc507ab8937573dca1ccfd2ed.zip | |
Add -Z simulate-remapped-rust-src-base option to simulate path virutalisation during bootstrapping
| -rw-r--r-- | compiler/rustc_interface/src/tests.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_session/src/options.rs | 3 | ||||
| -rw-r--r-- | src/test/codegen/remap_path_prefix/issue-73167-remap-std.rs | 9 |
4 files changed, 35 insertions, 3 deletions
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<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], 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"); |
