Skip to content

Commit 83cb760

Browse files
committed
run_make_support nm implementation + bin-emit-no-symbols rmake rewrite
1 parent 8814b92 commit 83cb760

File tree

12 files changed

+74
-17
lines changed

12 files changed

+74
-17
lines changed

src/doc/book

Submodule book updated 149 files

src/doc/reference

src/tools/cargo

Submodule cargo updated 285 files
+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
@@ -84,7 +84,6 @@ run-make/issue-37839/Makefile
8484
run-make/issue-40535/Makefile
8585
run-make/issue-47384/Makefile
8686
run-make/issue-47551/Makefile
87-
run-make/issue-51671/Makefile
8887
run-make/issue-68794-textrel-on-minimal-lib/Makefile
8988
run-make/issue-69368/Makefile
9089
run-make/issue-83045/Makefile
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 rmake_out_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)