Skip to content

Commit 83b80a6

Browse files
committed
use llvm-nm in symbol-visibility rmake test
1 parent dcaa17a commit 83b80a6

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

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

Lines changed: 30 additions & 0 deletions
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-nm` invocation. This assumes that `llvm-nm` is available
40+
/// at `$LLVM_BIN_DIR/llvm-nm`.
41+
pub fn llvm_nm() -> LlvmNm {
42+
LlvmNm::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-nm` invocation builder.
81+
#[derive(Debug)]
82+
#[must_use]
83+
pub struct LlvmNm {
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!(LlvmNm);
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 LlvmNm {
263+
/// Construct a new `llvm-nm` invocation. This assumes that `llvm-nm` is available
264+
/// at `$LLVM_BIN_DIR/llvm-nm`.
265+
pub fn new() -> Self {
266+
let llvm_nm = llvm_bin_dir().join("llvm-nm");
267+
let cmd = Command::new(llvm_nm);
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

Lines changed: 2 additions & 2 deletions
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_filecheck, llvm_nm, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr,
52+
LlvmFilecheck, LlvmNm, LlvmObjdump, LlvmProfdata, LlvmReadobj,
5353
};
5454
pub use python::python_command;
5555
pub use rustc::{aux_build, bare_rustc, rustc, Rustc};

tests/run-make/symbol-visibility/rmake.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
//@ ignore-windows-msvc
88

9-
use run_make_support::{bin_name, dynamic_lib_name, is_windows, llvm_readobj, regex, rustc};
9+
//FIXME(Oneirical): This currently uses llvm-nm for symbol detection. However,
10+
// the custom Rust-based solution of #128314 may prove to be an interesting alternative.
11+
12+
use run_make_support::{bin_name, dynamic_lib_name, is_darwin, is_windows, llvm_nm, regex, rustc};
1013

1114
fn main() {
12-
let mut cdylib_name = dynamic_lib_name("a_cdylib");
13-
let mut rdylib_name = dynamic_lib_name("a_rust_dylib");
15+
let cdylib_name = dynamic_lib_name("a_cdylib");
16+
let rdylib_name = dynamic_lib_name("a_rust_dylib");
1417
let exe_name = bin_name("an_executable");
15-
let mut combined_cdylib_name = dynamic_lib_name("combined_rlib_dylib");
18+
let combined_cdylib_name = dynamic_lib_name("combined_rlib_dylib");
1619
rustc().arg("-Zshare-generics=no").input("an_rlib.rs").run();
1720
rustc().arg("-Zshare-generics=no").input("a_cdylib.rs").run();
1821
rustc().arg("-Zshare-generics=no").input("a_rust_dylib.rs").run();
@@ -142,7 +145,15 @@ fn main() {
142145

143146
#[track_caller]
144147
fn symbols_check(path: &str, symbol_check_type: SymbolCheckType, exists_once: bool) {
145-
let out = llvm_readobj().arg("--dyn-symbols").input(path).run().invalid_stdout_utf8();
148+
let mut nm = llvm_nm();
149+
if is_windows() {
150+
nm.arg("--extern-only");
151+
} else if is_darwin() {
152+
nm.arg("--extern-only").arg("--defined-only");
153+
} else {
154+
nm.arg("--dynamic");
155+
}
156+
let out = nm.input(path).run().stdout_utf8();
146157
assert_eq!(
147158
out.lines()
148159
.filter(|&line| !line.contains("__imp_") && has_symbol(line, symbol_check_type))

0 commit comments

Comments
 (0)