Skip to content

Commit 5975414

Browse files
committed
Auto merge of #128410 - Oneirical:dwarf-fortestress, r=<try>
Migrate `remap-path-prefix-dwarf` `run-make` test to rmake Part of #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. try-job: aarch64-apple try-job: armhf-gnu try-job: test-various try-job: x86_64-gnu-llvm-18
2 parents fd8d6fb + bc72f04 commit 5975414

File tree

5 files changed

+235
-115
lines changed

5 files changed

+235
-115
lines changed

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

+30
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ pub fn llvm_bcanalyzer() -> LlvmBcanalyzer {
4848
LlvmBcanalyzer::new()
4949
}
5050

51+
/// Construct a new `llvm-dwarfdump` invocation. This assumes that `llvm-dwarfdump` is available
52+
/// at `$LLVM_BIN_DIR/llvm-dwarfdump`.
53+
pub fn llvm_dwarfdump() -> LlvmDwarfdump {
54+
LlvmDwarfdump::new()
55+
}
56+
5157
/// A `llvm-readobj` invocation builder.
5258
#[derive(Debug)]
5359
#[must_use]
@@ -97,13 +103,21 @@ pub struct LlvmBcanalyzer {
97103
cmd: Command,
98104
}
99105

106+
/// A `llvm-dwarfdump` invocation builder.
107+
#[derive(Debug)]
108+
#[must_use]
109+
pub struct LlvmDwarfdump {
110+
cmd: Command,
111+
}
112+
100113
crate::macros::impl_common_helpers!(LlvmReadobj);
101114
crate::macros::impl_common_helpers!(LlvmProfdata);
102115
crate::macros::impl_common_helpers!(LlvmFilecheck);
103116
crate::macros::impl_common_helpers!(LlvmObjdump);
104117
crate::macros::impl_common_helpers!(LlvmAr);
105118
crate::macros::impl_common_helpers!(LlvmNm);
106119
crate::macros::impl_common_helpers!(LlvmBcanalyzer);
120+
crate::macros::impl_common_helpers!(LlvmDwarfdump);
107121

108122
/// Generate the path to the bin directory of LLVM.
109123
#[must_use]
@@ -310,3 +324,19 @@ impl LlvmBcanalyzer {
310324
self
311325
}
312326
}
327+
328+
impl LlvmDwarfdump {
329+
/// Construct a new `llvm-dwarfdump` invocation. This assumes that `llvm-dwarfdump` is available
330+
/// at `$LLVM_BIN_DIR/llvm-dwarfdump`.
331+
pub fn new() -> Self {
332+
let llvm_dwarfdump = llvm_bin_dir().join("llvm-dwarfdump");
333+
let cmd = Command::new(llvm_dwarfdump);
334+
Self { cmd }
335+
}
336+
337+
/// Provide an input file.
338+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
339+
self.cmd.arg(path.as_ref());
340+
self
341+
}
342+
}

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

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

0 commit comments

Comments
 (0)