Skip to content

Commit efb69bf

Browse files
committed
run_make_support nm implementation + bin-emit-no-symbols rmake rewrite
1 parent 7feb191 commit efb69bf

File tree

6 files changed

+71
-10
lines changed

6 files changed

+71
-10
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod cc;
77
pub mod clang;
88
pub mod diff;
99
pub mod llvm_readobj;
10+
pub mod nm;
1011
pub mod run;
1112
pub mod rustc;
1213
pub mod rustdoc;
@@ -25,6 +26,7 @@ pub use wasmparser;
2526
pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
2627
pub use clang::{clang, Clang};
2728
pub use diff::{diff, Diff};
29+
pub use nm::{nm, Nm};
2830
pub use llvm_readobj::{llvm_readobj, LlvmReadobj};
2931
pub use run::{run, run_fail};
3032
pub use rustc::{aux_build, rustc, Rustc};
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use object::{Object, ObjectSection};
2+
use run_make_support::object;
3+
use std::fs::File as StdFile;
4+
5+
#[derive(Debug)]
6+
struct Nm {
7+
file: Option<object::File>,
8+
}
9+
10+
pub fn nm() -> Nm {
11+
Nm::new()
12+
}
13+
14+
impl Nm {
15+
/// Construct a bare `nm` invocation.
16+
pub fn new() -> Self {
17+
Self { file: None }
18+
}
19+
20+
/// Specify the file to analyze the symbols of.
21+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
22+
Self {
23+
file: Some(
24+
object::File::parse(
25+
fs::read(path)
26+
.expect(format!("Failed to open the ELF file at {:?}", &path.display())),
27+
)
28+
.expect(format!("Failed to parse ELF file at {:?}", &path.display())),
29+
),
30+
}
31+
}
32+
33+
/// Collect all symbols of an object file into a String.
34+
pub fn collect_symbols(&self) -> String {
35+
let object_file = self.file;
36+
let mut symbols_str = String::new();
37+
for section in object_file.sections() {
38+
if let Ok(ObjectSection::SymbolTable(st)) = section.parse::<object::SymbolTable>() {
39+
for symbol in st.symbols() {
40+
symbols_str.push_str(&format!(
41+
"{:016x} {:?} {}\n",
42+
symbol.address(),
43+
symbol.kind(),
44+
symbol.name()
45+
));
46+
}
47+
}
48+
}
49+
}
50+
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ run-make/issue-37839/Makefile
103103
run-make/issue-40535/Makefile
104104
run-make/issue-47384/Makefile
105105
run-make/issue-47551/Makefile
106-
run-make/issue-51671/Makefile
107106
run-make/issue-64153/Makefile
108107
run-make/issue-68794-textrel-on-minimal-lib/Makefile
109108
run-make/issue-69368/Makefile
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// When setting the crate type as a "bin" (in app.rs),
2+
// this could cause a bug where some symbols would not be
3+
// emitted in the object files. This has been fixed, and
4+
// this test checks that the correct symbols have been successfully
5+
// emitted inside the object files.
6+
// See https://github.com/rust-lang/rust/issues/51671
7+
8+
use run_make_support::{nm, rustc, tmp_dir};
9+
10+
fn main() {
11+
rustc().emit("obj").input("app.rs").run();
12+
//FIXME(Oneirical): This should eventually be tmp_path
13+
let nm = nm(tmp_dir().join("app.o"));
14+
assert!(
15+
nm.contains("rust_begin_unwind")
16+
&& nm.contains("rust_eh_personality")
17+
&& nm.contains("__rg_oom")
18+
);
19+
}

tests/run-make/issue-51671/Makefile

-9
This file was deleted.

0 commit comments

Comments
 (0)