mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
run_make_support nm implementation + bin-emit-no-symbols rmake rewrite
This commit is contained in:
+1
-1
Submodule library/backtrace updated: 72265bea21...5e05efa879
+1
-1
Submodule src/doc/book updated: 45c1a6d69e...5e9051f716
+1
-1
Submodule src/doc/edition-guide updated: cb58c430b4...bbaabbe088
+1
-1
Submodule src/doc/reference updated: 0b805c6580...6019b76f5b
+1
-1
Submodule src/doc/rust-by-example updated: b1d97bd611...4840dca06c
+1
-1
Submodule src/doc/rustc-dev-guide updated: aec82168dd...6a7374bd87
+1
-1
Submodule src/tools/cargo updated: a1f47ec3f7...431db31d0d
@@ -0,0 +1,48 @@
|
||||
use crate::{fs_wrapper, object};
|
||||
use object::{Object, ObjectSection};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Nm {
|
||||
file: Option<object::File>,
|
||||
}
|
||||
|
||||
pub fn nm() -> Nm {
|
||||
Nm::new()
|
||||
}
|
||||
|
||||
impl Nm {
|
||||
/// Construct a bare `nm` invocation.
|
||||
pub fn new() -> Self {
|
||||
Self { file: None }
|
||||
}
|
||||
|
||||
/// Specify the file to analyze the symbols of.
|
||||
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
||||
&mut Self {
|
||||
file: Some(
|
||||
object::File::parse(fs_wrapper::read(path))
|
||||
.expect(format!("Failed to parse ELF file at {:?}", path.as_ref().display())),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Collect all symbols of an object file into a String.
|
||||
pub fn collect_symbols(&self) -> String {
|
||||
let object_file = self.file;
|
||||
let mut symbols_str = String::new();
|
||||
for section in object_file.sections() {
|
||||
if let Ok(ObjectSection::SymbolTable(st)) = section.parse::<object::SymbolTable>() {
|
||||
for symbol in st.symbols() {
|
||||
symbols_str.push_str(&format!(
|
||||
"{:016x} {:?} {}\n",
|
||||
symbol.address(),
|
||||
symbol.kind(),
|
||||
symbol.name()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
symbols_str
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,6 @@ run-make/issue-37839/Makefile
|
||||
run-make/issue-40535/Makefile
|
||||
run-make/issue-47384/Makefile
|
||||
run-make/issue-47551/Makefile
|
||||
run-make/issue-51671/Makefile
|
||||
run-make/issue-68794-textrel-on-minimal-lib/Makefile
|
||||
run-make/issue-69368/Makefile
|
||||
run-make/issue-83045/Makefile
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// When setting the crate type as a "bin" (in app.rs),
|
||||
// this could cause a bug where some symbols would not be
|
||||
// emitted in the object files. This has been fixed, and
|
||||
// this test checks that the correct symbols have been successfully
|
||||
// emitted inside the object files.
|
||||
// See https://github.com/rust-lang/rust/issues/51671
|
||||
|
||||
use run_make_support::{nm, rustc, tmp_dir};
|
||||
|
||||
fn main() {
|
||||
rustc().emit("obj").input("app.rs").run();
|
||||
//FIXME(Oneirical): This should eventually be rmake_out_path
|
||||
let nm = nm(tmp_dir().join("app.o"));
|
||||
assert!(
|
||||
nm.contains("rust_begin_unwind")
|
||||
&& nm.contains("rust_eh_personality")
|
||||
&& nm.contains("__rg_oom")
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
include ../tools.mk
|
||||
|
||||
# ignore-windows-msvc
|
||||
|
||||
all:
|
||||
$(RUSTC) --emit=obj app.rs
|
||||
nm $(TMPDIR)/app.o | $(CGREP) rust_begin_unwind
|
||||
nm $(TMPDIR)/app.o | $(CGREP) rust_eh_personality
|
||||
nm $(TMPDIR)/app.o | $(CGREP) __rg_oom
|
||||
Reference in New Issue
Block a user