Skip to content

Commit ef743af

Browse files
committed
run-make-support: add llvm-dis and llvm-objcopy
1 parent 562d08e commit ef743af

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

Diff for: src/tools/run-make-support/src/external_deps/llvm.rs

+66
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ pub fn llvm_pdbutil() -> LlvmPdbutil {
6060
LlvmPdbutil::new()
6161
}
6262

63+
/// Construct a new `llvm-dis` invocation. This assumes that `llvm-dis` is available
64+
/// at `$LLVM_BIN_DIR/llvm-dis`.
65+
pub fn llvm_dis() -> LlvmDis {
66+
LlvmDis::new()
67+
}
68+
69+
/// Construct a new `llvm-objcopy` invocation. This assumes that `llvm-objcopy` is available
70+
/// at `$LLVM_BIN_DIR/llvm-objcopy`.
71+
pub fn llvm_objcopy() -> LlvmObjcopy {
72+
LlvmObjcopy::new()
73+
}
74+
6375
/// A `llvm-readobj` invocation builder.
6476
#[derive(Debug)]
6577
#[must_use]
@@ -123,6 +135,20 @@ pub struct LlvmPdbutil {
123135
cmd: Command,
124136
}
125137

138+
/// A `llvm-dis` invocation builder.
139+
#[derive(Debug)]
140+
#[must_use]
141+
pub struct LlvmDis {
142+
cmd: Command,
143+
}
144+
145+
/// A `llvm-objcopy` invocation builder.
146+
#[derive(Debug)]
147+
#[must_use]
148+
pub struct LlvmObjcopy {
149+
cmd: Command,
150+
}
151+
126152
crate::macros::impl_common_helpers!(LlvmReadobj);
127153
crate::macros::impl_common_helpers!(LlvmProfdata);
128154
crate::macros::impl_common_helpers!(LlvmFilecheck);
@@ -132,6 +158,8 @@ crate::macros::impl_common_helpers!(LlvmNm);
132158
crate::macros::impl_common_helpers!(LlvmBcanalyzer);
133159
crate::macros::impl_common_helpers!(LlvmDwarfdump);
134160
crate::macros::impl_common_helpers!(LlvmPdbutil);
161+
crate::macros::impl_common_helpers!(LlvmDis);
162+
crate::macros::impl_common_helpers!(LlvmObjcopy);
135163

136164
/// Generate the path to the bin directory of LLVM.
137165
#[must_use]
@@ -390,3 +418,41 @@ impl LlvmPdbutil {
390418
self
391419
}
392420
}
421+
422+
impl LlvmObjcopy {
423+
/// Construct a new `llvm-objcopy` invocation. This assumes that `llvm-objcopy` is available
424+
/// at `$LLVM_BIN_DIR/llvm-objcopy`.
425+
pub fn new() -> Self {
426+
let llvm_objcopy = llvm_bin_dir().join("llvm-objcopy");
427+
let cmd = Command::new(llvm_objcopy);
428+
Self { cmd }
429+
}
430+
431+
/// Dump the contents of `section` into the file at `path`.
432+
#[track_caller]
433+
pub fn dump_section<S: AsRef<str>, P: AsRef<Path>>(
434+
&mut self,
435+
section_name: S,
436+
path: P,
437+
) -> &mut Self {
438+
self.cmd.arg("--dump-section");
439+
self.cmd.arg(format!("{}={}", section_name.as_ref(), path.as_ref().to_str().unwrap()));
440+
self
441+
}
442+
}
443+
444+
impl LlvmDis {
445+
/// Construct a new `llvm-dis` invocation. This assumes that `llvm-dis` is available
446+
/// at `$LLVM_BIN_DIR/llvm-dis`.
447+
pub fn new() -> Self {
448+
let llvm_dis = llvm_bin_dir().join("llvm-dis");
449+
let cmd = Command::new(llvm_dis);
450+
Self { cmd }
451+
}
452+
453+
/// Provide an input file.
454+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
455+
self.cmd.arg(path.as_ref());
456+
self
457+
}
458+
}

Diff for: src/tools/run-make-support/src/lib.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rust
4949

5050
// These rely on external dependencies.
5151
pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
52-
pub use c_build::{build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_optimized, build_native_static_lib_cxx};
52+
pub use c_build::{
53+
build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_cxx,
54+
build_native_static_lib_optimized,
55+
};
5356
pub use cargo::cargo;
5457
pub use clang::{clang, Clang};
5558
pub use htmldocck::htmldocck;
5659
pub use llvm::{
57-
llvm_ar, llvm_bcanalyzer, llvm_dwarfdump, llvm_filecheck, llvm_nm, llvm_objdump, llvm_profdata,
58-
llvm_readobj, LlvmAr, LlvmBcanalyzer, LlvmDwarfdump, LlvmFilecheck, LlvmNm, LlvmObjdump,
59-
LlvmProfdata, LlvmReadobj,
60+
llvm_ar, llvm_bcanalyzer, llvm_dis, llvm_dwarfdump, llvm_filecheck, llvm_nm, llvm_objcopy,
61+
llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmBcanalyzer, LlvmDis, LlvmDwarfdump,
62+
LlvmFilecheck, LlvmNm, LlvmObjcopy, LlvmObjdump, LlvmProfdata, LlvmReadobj,
6063
};
6164
pub use python::python_command;
6265
pub use rustc::{aux_build, bare_rustc, rustc, rustc_path, Rustc};

0 commit comments

Comments
 (0)