Skip to content

Commit 4ab97c7

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

File tree

6 files changed

+69
-10
lines changed

6 files changed

+69
-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;
@@ -26,6 +27,7 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
2627
pub use clang::{clang, Clang};
2728
pub use diff::{diff, Diff};
2829
pub use llvm_readobj::{llvm_readobj, LlvmReadobj};
30+
pub use nm::{nm, Nm};
2931
pub use run::{run, run_fail};
3032
pub use rustc::{aux_build, rustc, Rustc};
3133
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use crate::{fs_wrapper, object};
2+
use object::{Object, ObjectSection};
3+
use std::path::Path;
4+
5+
#[derive(Debug)]
6+
pub 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+
&mut Self {
23+
file: Some(
24+
object::File::parse(fs_wrapper::read(path))
25+
.expect(format!("Failed to parse ELF file at {:?}", path.as_ref().display())),
26+
),
27+
}
28+
}
29+
30+
/// Collect all symbols of an object file into a String.
31+
pub fn collect_symbols(&self) -> String {
32+
let object_file = self.file;
33+
let mut symbols_str = String::new();
34+
for section in object_file.sections() {
35+
if let Ok(ObjectSection::SymbolTable(st)) = section.parse::<object::SymbolTable>() {
36+
for symbol in st.symbols() {
37+
symbols_str.push_str(&format!(
38+
"{:016x} {:?} {}\n",
39+
symbol.address(),
40+
symbol.kind(),
41+
symbol.name()
42+
));
43+
}
44+
}
45+
}
46+
symbols_str
47+
}
48+
}

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)