From cf8b87b0d156a34773979a564b641d0c513273e1 Mon Sep 17 00:00:00 2001 From: Florian Schmiderer Date: Fri, 6 Sep 2024 23:35:18 +0200 Subject: [PATCH 1/3] run-make-support: Add llvm-pdbutil --- .../src/external_deps/llvm.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/tools/run-make-support/src/external_deps/llvm.rs b/src/tools/run-make-support/src/external_deps/llvm.rs index e9315856cd775..d6e1f96e395fe 100644 --- a/src/tools/run-make-support/src/external_deps/llvm.rs +++ b/src/tools/run-make-support/src/external_deps/llvm.rs @@ -110,6 +110,13 @@ pub struct LlvmDwarfdump { cmd: Command, } +/// A `llvm-dwarfdump` invocation builder. +#[derive(Debug)] +#[must_use] +pub struct LlvmPdbutil { + cmd: Command, +} + crate::macros::impl_common_helpers!(LlvmReadobj); crate::macros::impl_common_helpers!(LlvmProfdata); crate::macros::impl_common_helpers!(LlvmFilecheck); @@ -118,6 +125,7 @@ crate::macros::impl_common_helpers!(LlvmAr); crate::macros::impl_common_helpers!(LlvmNm); crate::macros::impl_common_helpers!(LlvmBcanalyzer); crate::macros::impl_common_helpers!(LlvmDwarfdump); +crate::macros::impl_common_helpers!(LlvmPdbutil); /// Generate the path to the bin directory of LLVM. #[must_use] @@ -359,3 +367,19 @@ impl LlvmDwarfdump { self } } + +impl LlvmPdbutil { + /// Construct a new `llvm-pdbutil` invocation. This assumes that `llvm-pdbutil` is available + /// at `$LLVM_BIN_DIR/llvm-pdbutil`. + pub fn new() -> Self { + let llvm_pdbutil = llvm_bin_dir().join("llvm-pdbutil"); + let cmd = Command::new(llvm_pdbutil); + Self { cmd } + } + + /// Provide an input file. + pub fn input>(&mut self, path: P) -> &mut Self { + self.cmd.arg(path.as_ref()); + self + } +} From c02ea321c56a5f5f33b533ddd102b7bf438fffe7 Mon Sep 17 00:00:00 2001 From: Florian Schmiderer Date: Fri, 6 Sep 2024 23:38:54 +0200 Subject: [PATCH 2/3] Add Unit test for S_OBJNAME --- tests/run-make/pdb-sobjname/filecheck.txt | 1 + tests/run-make/pdb-sobjname/main.rs | 1 + tests/run-make/pdb-sobjname/rmake.rs | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/run-make/pdb-sobjname/filecheck.txt create mode 100644 tests/run-make/pdb-sobjname/main.rs create mode 100644 tests/run-make/pdb-sobjname/rmake.rs diff --git a/tests/run-make/pdb-sobjname/filecheck.txt b/tests/run-make/pdb-sobjname/filecheck.txt new file mode 100644 index 0000000000000..80e5c0037e8b2 --- /dev/null +++ b/tests/run-make/pdb-sobjname/filecheck.txt @@ -0,0 +1 @@ +CHECK: S_OBJNAME{{.+}}my_great_crate_name{{.+}}.o \ No newline at end of file diff --git a/tests/run-make/pdb-sobjname/main.rs b/tests/run-make/pdb-sobjname/main.rs new file mode 100644 index 0000000000000..f328e4d9d04c3 --- /dev/null +++ b/tests/run-make/pdb-sobjname/main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/run-make/pdb-sobjname/rmake.rs b/tests/run-make/pdb-sobjname/rmake.rs new file mode 100644 index 0000000000000..00ab347f21809 --- /dev/null +++ b/tests/run-make/pdb-sobjname/rmake.rs @@ -0,0 +1,18 @@ +// Check if the pdb file contains an S_OBJNAME entry with the name of the .o file + +// This is because it used to be missing in #96475. +// See https://github.com/rust-lang/rust/pull/115704 + +//@ only-windows-msvc +// Reason: pdb files are unique to this architecture + +use run_make_support::{llvm, rustc}; + +fn main() { + rustc().input("main.rs").arg("-g").crate_name("my_great_crate_name").crate_type("bin").run(); + + let pdbutil_result = + llvm::LlvmPdbutil::new().arg("dump").arg("-symbols").input("my_great_crate_name.pdb").run(); + + llvm::llvm_filecheck().patterns("filecheck.txt").stdin(pdbutil_result.stdout_utf8()).run(); +} From e3d8bb8b3ce264ba4abfae2673063aa0c3362bf6 Mon Sep 17 00:00:00 2001 From: Florian Schmiderer Date: Fri, 6 Sep 2024 23:41:16 +0200 Subject: [PATCH 3/3] Update test for LF_BUILDINFO cl and cmd --- .../pdb-buildinfo-cl-cmd/filecheck.txt | 4 ++++ tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs | 24 ++++--------------- 2 files changed, 9 insertions(+), 19 deletions(-) create mode 100644 tests/run-make/pdb-buildinfo-cl-cmd/filecheck.txt diff --git a/tests/run-make/pdb-buildinfo-cl-cmd/filecheck.txt b/tests/run-make/pdb-buildinfo-cl-cmd/filecheck.txt new file mode 100644 index 0000000000000..a01999d5bdf76 --- /dev/null +++ b/tests/run-make/pdb-buildinfo-cl-cmd/filecheck.txt @@ -0,0 +1,4 @@ +CHECK: LF_BUILDINFO +CHECK: rustc.exe +CHECK: main.rs +CHECK: "-g" "--crate-name" "my_crate_name" "--crate-type" "bin" "-Cmetadata=dc9ef878b0a48666" diff --git a/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs b/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs index 2ab9057b24c1b..30f8f7bc9fbae 100644 --- a/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs +++ b/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs @@ -7,7 +7,7 @@ //@ only-windows-msvc // Reason: pdb files are unique to this architecture -use run_make_support::{assert_contains, bstr, env_var, rfs, rustc}; +use run_make_support::{llvm, rustc}; fn main() { rustc() @@ -17,23 +17,9 @@ fn main() { .crate_type("bin") .metadata("dc9ef878b0a48666") .run(); - let tests = [ - &env_var("RUSTC"), - r#""main.rs""#, - r#""-g""#, - r#""--crate-name""#, - r#""my_crate_name""#, - r#""--crate-type""#, - r#""bin""#, - r#""-Cmetadata=dc9ef878b0a48666""#, - ]; - for test in tests { - assert_pdb_contains(test); - } -} -fn assert_pdb_contains(needle: &str) { - let needle = needle.as_bytes(); - use bstr::ByteSlice; - assert!(&rfs::read("my_crate_name.pdb").find(needle).is_some()); + let pdbutil_result = + llvm::LlvmPdbutil::new().arg("dump").arg("-ids").input("my_crate_name.pdb").run(); + + llvm::llvm_filecheck().patterns("filecheck.txt").stdin(pdbutil_result.stdout_utf8()).run(); }