Skip to content

Commit 39fd25d

Browse files
committed
Auto merge of rust-lang#128410 - Oneirical:dwarf-fortestress, r=<try>
Migrate `remap-path-prefix-dwarf` `run-make` test to rmake Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). Possibly my proudest branch name yet. Please try: try-job: x86_64-mingw try-job: i686-msvc
2 parents f8060d2 + faa6a16 commit 39fd25d

File tree

5 files changed

+233
-115
lines changed

5 files changed

+233
-115
lines changed

src/tools/run-make-support/src/external_deps/llvm.rs

+30
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ pub fn llvm_ar() -> LlvmAr {
3636
LlvmAr::new()
3737
}
3838

39+
/// Construct a new `llvm-dwarfdump` invocation. This assumes that `llvm-dwarfdump` is available
40+
/// at `$LLVM_BIN_DIR/llvm-dwarfdump`.
41+
pub fn llvm_dwarfdump() -> LlvmDwarfdump {
42+
LlvmDwarfdump::new()
43+
}
44+
3945
/// A `llvm-readobj` invocation builder.
4046
#[derive(Debug)]
4147
#[must_use]
@@ -71,11 +77,19 @@ pub struct LlvmAr {
7177
cmd: Command,
7278
}
7379

80+
/// A `llvm-dwarfdump` invocation builder.
81+
#[derive(Debug)]
82+
#[must_use]
83+
pub struct LlvmDwarfdump {
84+
cmd: Command,
85+
}
86+
7487
crate::macros::impl_common_helpers!(LlvmReadobj);
7588
crate::macros::impl_common_helpers!(LlvmProfdata);
7689
crate::macros::impl_common_helpers!(LlvmFilecheck);
7790
crate::macros::impl_common_helpers!(LlvmObjdump);
7891
crate::macros::impl_common_helpers!(LlvmAr);
92+
crate::macros::impl_common_helpers!(LlvmDwarfdump);
7993

8094
/// Generate the path to the bin directory of LLVM.
8195
#[must_use]
@@ -244,3 +258,19 @@ impl LlvmAr {
244258
self
245259
}
246260
}
261+
262+
impl LlvmDwarfdump {
263+
/// Construct a new `llvm-dwarfdump` invocation. This assumes that `llvm-dwarfdump` is available
264+
/// at `$LLVM_BIN_DIR/llvm-dwarfdump`.
265+
pub fn new() -> Self {
266+
let llvm_dwarfdump = llvm_bin_dir().join("llvm-dwarfdump");
267+
let cmd = Command::new(llvm_dwarfdump);
268+
Self { cmd }
269+
}
270+
271+
/// Provide an input file.
272+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
273+
self.cmd.arg(path.as_ref());
274+
self
275+
}
276+
}

src/tools/run-make-support/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
4848
pub use clang::{clang, Clang};
4949
pub use htmldocck::htmldocck;
5050
pub use llvm::{
51-
llvm_ar, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmFilecheck,
52-
LlvmObjdump, LlvmProfdata, LlvmReadobj,
51+
llvm_ar, llvm_dwarfdump, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr,
52+
LlvmDwarfdump, LlvmFilecheck, LlvmObjdump, LlvmProfdata, LlvmReadobj,
5353
};
5454
pub use python::python_command;
5555
pub use rustc::{aux_build, bare_rustc, rustc, Rustc};

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ run-make/print-target-list/Makefile
4242
run-make/raw-dylib-alt-calling-convention/Makefile
4343
run-make/raw-dylib-c/Makefile
4444
run-make/redundant-libs/Makefile
45-
run-make/remap-path-prefix-dwarf/Makefile
4645
run-make/reproducible-build-2/Makefile
4746
run-make/reproducible-build/Makefile
4847
run-make/rlib-format-packed-bundled-libs-2/Makefile

tests/run-make/remap-path-prefix-dwarf/Makefile

-112
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
// This test makes sure that --remap-path-prefix has the expected effects on paths in debuginfo.
2+
// We explicitly switch to a directory that *is* a prefix of the directory our
3+
// source code is contained in.
4+
// It tests several cases, each of them has a detailed description attached to it.
5+
// See https://github.com/rust-lang/rust/pull/96867
6+
7+
//FIXME(Oneirical): try it on windows
8+
9+
use run_make_support::{cwd, is_darwin, llvm_dwarfdump, rust_lib_name, rustc};
10+
11+
fn main() {
12+
// The compiler is called with an *ABSOLUTE PATH* as input, and that absolute path *is* within
13+
// the working directory of the compiler. We are remapping the path that contains `src`.
14+
check_dwarf(DwarfTest {
15+
lib_name: "abs_input_inside_working_dir",
16+
input_path: PathType::Absolute,
17+
scope: None,
18+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
19+
dwarf_test: DwarfDump::ContainsSrcPath,
20+
});
21+
check_dwarf(DwarfTest {
22+
lib_name: "abs_input_inside_working_dir_scope",
23+
input_path: PathType::Absolute,
24+
scope: Some(ScopeType::Object),
25+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
26+
dwarf_test: DwarfDump::ContainsSrcPath,
27+
});
28+
// The compiler is called with an *ABSOLUTE PATH* as input, and that absolute path is *not*
29+
// within the working directory of the compiler. We are remapping both the path that contains
30+
// `src` and the working directory to the same thing. This setup corresponds to a workaround
31+
// that is needed when trying to remap everything to something that looks like a local
32+
// path. Relative paths are interpreted as relative to the compiler's working directory (e.g.
33+
// in debuginfo). If we also remap the working directory, the compiler strip it from other
34+
// paths so that the final outcome is the desired one again.
35+
check_dwarf(DwarfTest {
36+
lib_name: "abs_input_outside_working_dir",
37+
input_path: PathType::Absolute,
38+
scope: None,
39+
remap_path_prefix: PrefixType::Dual((
40+
format!("{}=REMAPPED", cwd().display()),
41+
"rmake_out=REMAPPED".to_owned(),
42+
)),
43+
dwarf_test: DwarfDump::ContainsSrcPath,
44+
});
45+
// The compiler is called with a *RELATIVE PATH* as input. We are remapping the working
46+
// directory of the compiler, which naturally is an implicit prefix of our relative input path.
47+
// Debuginfo will expand the relative path to an absolute path and we expect the working
48+
// directory to be remapped in that expansion.
49+
check_dwarf(DwarfTest {
50+
lib_name: "rel_input_remap_working_dir",
51+
input_path: PathType::Relative,
52+
scope: None,
53+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
54+
dwarf_test: DwarfDump::ContainsSrcPath,
55+
});
56+
check_dwarf(DwarfTest {
57+
lib_name: "rel_input_remap_working_dir_scope",
58+
input_path: PathType::Relative,
59+
scope: Some(ScopeType::Object),
60+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
61+
dwarf_test: DwarfDump::ContainsSrcPath,
62+
});
63+
check_dwarf(DwarfTest {
64+
lib_name: "rel_input_remap_working_dir_scope",
65+
input_path: PathType::Relative,
66+
scope: Some(ScopeType::Diagnostics),
67+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().display())),
68+
dwarf_test: DwarfDump::AvoidSrcPath,
69+
});
70+
// The compiler is called with a *RELATIVE PATH* as input. We are remapping a *SUB-DIRECTORY*
71+
// of the compiler's working directory. This test makes sure that that directory is remapped
72+
// even though it won't actually show up in this form in the compiler's SourceMap and instead
73+
// is only constructed on demand during debuginfo generation.
74+
check_dwarf(DwarfTest {
75+
lib_name: "rel_input_remap_working_dir_child",
76+
input_path: PathType::Relative,
77+
scope: None,
78+
remap_path_prefix: PrefixType::Regular(format!("{}=REMAPPED", cwd().join("src").display())),
79+
dwarf_test: DwarfDump::ChildTest,
80+
});
81+
// The compiler is called with a *RELATIVE PATH* as input. We are remapping a
82+
// *PARENT DIRECTORY* of the compiler's working directory.
83+
check_dwarf(DwarfTest {
84+
lib_name: "rel_input_remap_working_dir_parent",
85+
input_path: PathType::Relative,
86+
scope: None,
87+
remap_path_prefix: PrefixType::Regular(format!(
88+
"{}=REMAPPED",
89+
cwd().parent().unwrap().display()
90+
)),
91+
dwarf_test: DwarfDump::ParentTest,
92+
});
93+
}
94+
95+
#[track_caller]
96+
fn check_dwarf(test: DwarfTest) {
97+
let mut rustc = rustc();
98+
match test.input_path {
99+
PathType::Absolute => rustc.input(cwd().join("src/quux.rs")),
100+
PathType::Relative => rustc.input("src/quux.rs"),
101+
};
102+
rustc.output(rust_lib_name(test.lib_name));
103+
rustc.arg("-Cdebuginfo=2");
104+
if let Some(scope) = test.scope {
105+
match scope {
106+
ScopeType::Object => rustc.arg("-Zremap-path-scope=object"),
107+
ScopeType::Diagnostics => rustc.arg("-Zremap-path-scope=diagnostics"),
108+
};
109+
if is_darwin() {
110+
rustc.arg("-Csplit-debuginfo=off");
111+
}
112+
}
113+
match test.remap_path_prefix {
114+
PrefixType::Regular(prefix) => {
115+
// We explicitly switch to a directory that *is* a prefix of the directory our
116+
// source code is contained in.
117+
rustc.arg("--remap-path-prefix");
118+
rustc.arg(prefix);
119+
}
120+
PrefixType::Dual((prefix1, prefix2)) => {
121+
// We explicitly switch to a directory that is *not* a prefix of the directory our
122+
// source code is contained in.
123+
rustc.arg("--remap-path-prefix");
124+
rustc.arg(prefix1);
125+
rustc.arg("--remap-path-prefix");
126+
rustc.arg(prefix2);
127+
}
128+
}
129+
rustc.run();
130+
match test.dwarf_test {
131+
DwarfDump::ContainsSrcPath => {
132+
llvm_dwarfdump()
133+
.input(rust_lib_name(test.lib_name))
134+
.run()
135+
// We expect the path to the main source file to be remapped.
136+
.assert_stdout_contains("REMAPPED/src/quux.rs")
137+
// No weird duplication of remapped components (see #78479)
138+
.assert_stdout_not_contains("REMAPPED/REMAPPED");
139+
}
140+
DwarfDump::AvoidSrcPath => {
141+
llvm_dwarfdump()
142+
.input(rust_lib_name(test.lib_name))
143+
.run()
144+
.assert_stdout_not_contains("REMAPPED/src/quux.rs")
145+
.assert_stdout_not_contains("REMAPPED/REMAPPED");
146+
}
147+
DwarfDump::ChildTest => {
148+
llvm_dwarfdump()
149+
.input(rust_lib_name(test.lib_name))
150+
.run()
151+
// We expect `src/quux.rs` to have been remapped to `REMAPPED/quux.rs`.
152+
.assert_stdout_contains("REMAPPED/quux.rs")
153+
// We don't want to find the path that we just remapped anywhere in the DWARF
154+
.assert_stdout_not_contains(cwd().join("src").to_str().unwrap())
155+
// No weird duplication of remapped components (see #78479)
156+
.assert_stdout_not_contains("REMAPPED/REMAPPED");
157+
}
158+
DwarfDump::ParentTest => {
159+
llvm_dwarfdump()
160+
.input(rust_lib_name(test.lib_name))
161+
.run()
162+
// We expect `src/quux.rs` to have been remapped to
163+
// `REMAPPED/remap-path-prefix-dwarf/src/quux.rs`.
164+
.assert_stdout_contains("REMAPPED/rmake_out/src/quux.rs")
165+
// We don't want to find the path that we just remapped anywhere in the DWARF
166+
.assert_stdout_not_contains(cwd().parent().unwrap().to_str().unwrap())
167+
// No weird duplication of remapped components (see #78479)
168+
.assert_stdout_not_contains("REMAPPED/REMAPPED");
169+
}
170+
};
171+
}
172+
173+
struct DwarfTest {
174+
lib_name: &'static str,
175+
input_path: PathType,
176+
scope: Option<ScopeType>,
177+
remap_path_prefix: PrefixType,
178+
dwarf_test: DwarfDump,
179+
}
180+
181+
enum PathType {
182+
Absolute,
183+
Relative,
184+
}
185+
186+
enum ScopeType {
187+
Object,
188+
Diagnostics,
189+
}
190+
191+
enum DwarfDump {
192+
ContainsSrcPath,
193+
AvoidSrcPath,
194+
ChildTest,
195+
ParentTest,
196+
}
197+
198+
enum PrefixType {
199+
Regular(String),
200+
Dual((String, String)),
201+
}

0 commit comments

Comments
 (0)