about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-10-18 17:34:11 +0800
committer许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-10-22 19:43:22 +0800
commitef743af119f9f244d47d3857c33c92ed2e217020 (patch)
tree5ed0dfc9fcb9c2568badef7447f91100ef73899a
parent562d08ee27a4348e7b1ebce2e6c8ac29f9ee213d (diff)
downloadrust-ef743af119f9f244d47d3857c33c92ed2e217020.tar.gz
rust-ef743af119f9f244d47d3857c33c92ed2e217020.zip
run-make-support: add `llvm-dis` and `llvm-objcopy`
-rw-r--r--src/tools/run-make-support/src/external_deps/llvm.rs66
-rw-r--r--src/tools/run-make-support/src/lib.rs11
2 files changed, 73 insertions, 4 deletions
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 38a9ac923b4..9a6e35da3fe 100644
--- a/src/tools/run-make-support/src/external_deps/llvm.rs
+++ b/src/tools/run-make-support/src/external_deps/llvm.rs
@@ -60,6 +60,18 @@ pub fn llvm_pdbutil() -> LlvmPdbutil {
     LlvmPdbutil::new()
 }
 
+/// Construct a new `llvm-dis` invocation. This assumes that `llvm-dis` is available
+/// at `$LLVM_BIN_DIR/llvm-dis`.
+pub fn llvm_dis() -> LlvmDis {
+    LlvmDis::new()
+}
+
+/// Construct a new `llvm-objcopy` invocation. This assumes that `llvm-objcopy` is available
+/// at `$LLVM_BIN_DIR/llvm-objcopy`.
+pub fn llvm_objcopy() -> LlvmObjcopy {
+    LlvmObjcopy::new()
+}
+
 /// A `llvm-readobj` invocation builder.
 #[derive(Debug)]
 #[must_use]
@@ -123,6 +135,20 @@ pub struct LlvmPdbutil {
     cmd: Command,
 }
 
+/// A `llvm-dis` invocation builder.
+#[derive(Debug)]
+#[must_use]
+pub struct LlvmDis {
+    cmd: Command,
+}
+
+/// A `llvm-objcopy` invocation builder.
+#[derive(Debug)]
+#[must_use]
+pub struct LlvmObjcopy {
+    cmd: Command,
+}
+
 crate::macros::impl_common_helpers!(LlvmReadobj);
 crate::macros::impl_common_helpers!(LlvmProfdata);
 crate::macros::impl_common_helpers!(LlvmFilecheck);
@@ -132,6 +158,8 @@ crate::macros::impl_common_helpers!(LlvmNm);
 crate::macros::impl_common_helpers!(LlvmBcanalyzer);
 crate::macros::impl_common_helpers!(LlvmDwarfdump);
 crate::macros::impl_common_helpers!(LlvmPdbutil);
+crate::macros::impl_common_helpers!(LlvmDis);
+crate::macros::impl_common_helpers!(LlvmObjcopy);
 
 /// Generate the path to the bin directory of LLVM.
 #[must_use]
@@ -390,3 +418,41 @@ impl LlvmPdbutil {
         self
     }
 }
+
+impl LlvmObjcopy {
+    /// Construct a new `llvm-objcopy` invocation. This assumes that `llvm-objcopy` is available
+    /// at `$LLVM_BIN_DIR/llvm-objcopy`.
+    pub fn new() -> Self {
+        let llvm_objcopy = llvm_bin_dir().join("llvm-objcopy");
+        let cmd = Command::new(llvm_objcopy);
+        Self { cmd }
+    }
+
+    /// Dump the contents of `section` into the file at `path`.
+    #[track_caller]
+    pub fn dump_section<S: AsRef<str>, P: AsRef<Path>>(
+        &mut self,
+        section_name: S,
+        path: P,
+    ) -> &mut Self {
+        self.cmd.arg("--dump-section");
+        self.cmd.arg(format!("{}={}", section_name.as_ref(), path.as_ref().to_str().unwrap()));
+        self
+    }
+}
+
+impl LlvmDis {
+    /// Construct a new `llvm-dis` invocation. This assumes that `llvm-dis` is available
+    /// at `$LLVM_BIN_DIR/llvm-dis`.
+    pub fn new() -> Self {
+        let llvm_dis = llvm_bin_dir().join("llvm-dis");
+        let cmd = Command::new(llvm_dis);
+        Self { cmd }
+    }
+
+    /// Provide an input file.
+    pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
+        self.cmd.arg(path.as_ref());
+        self
+    }
+}
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index 15d813ccf53..368b98c9f0d 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -49,14 +49,17 @@ pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rust
 
 // These rely on external dependencies.
 pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
-pub use c_build::{build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_optimized, build_native_static_lib_cxx};
+pub use c_build::{
+    build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_cxx,
+    build_native_static_lib_optimized,
+};
 pub use cargo::cargo;
 pub use clang::{clang, Clang};
 pub use htmldocck::htmldocck;
 pub use llvm::{
-    llvm_ar, llvm_bcanalyzer, llvm_dwarfdump, llvm_filecheck, llvm_nm, llvm_objdump, llvm_profdata,
-    llvm_readobj, LlvmAr, LlvmBcanalyzer, LlvmDwarfdump, LlvmFilecheck, LlvmNm, LlvmObjdump,
-    LlvmProfdata, LlvmReadobj,
+    llvm_ar, llvm_bcanalyzer, llvm_dis, llvm_dwarfdump, llvm_filecheck, llvm_nm, llvm_objcopy,
+    llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmBcanalyzer, LlvmDis, LlvmDwarfdump,
+    LlvmFilecheck, LlvmNm, LlvmObjcopy, LlvmObjdump, LlvmProfdata, LlvmReadobj,
 };
 pub use python::python_command;
 pub use rustc::{aux_build, bare_rustc, rustc, rustc_path, Rustc};