Skip to content

Commit a613213

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

File tree

7 files changed

+54
-10
lines changed

7 files changed

+54
-10
lines changed

src/tools/run-make-support/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ similar = "2.5.0"
99
wasmparser = "0.118.2"
1010
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
1111
gimli = "0.28.1"
12+
goblin = "0.8.2"

src/tools/run-make-support/nm/mod.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use goblin::elf::Elf32;
2+
use goblin::elf::Elf64;
3+
use goblin::elf::SectionHeader;
4+
use std::fs::File as StdFile;
5+
6+
pub fn nm<P: AsRef<Path>>(path: P) -> String {
7+
// Determine whether the file is 32-bit or 64-bit
8+
// by fetching the target's configuration
9+
let file = File::open(&path).expect(format!("Failed to open the ELF file at {:?}", &path.display())) {
10+
let mut elf = if cfg!(target_pointer_width = 64) {
11+
Elf64::new(file)
12+
} else if cfg!(target_pointer_width = 32) {
13+
Elf32::new(file)
14+
} else {
15+
panic!("Unsupported architecture detected, should be 32 or 64 bits.")
16+
};
17+
18+
let mut all_symbol_names = String::new();
19+
20+
let symtab_section_index = elf.section_headers()
21+
.iter()
22+
.position(|sh| sh.sh_type == SectionHeader::SHT_SYMTAB)
23+
.expect("Symbol table section not found");
24+
25+
for symbol in elf.symbol_table(symtab_section_index).symbols() {
26+
all_symbol_names.push_str(&symbol.name.to_string_lossy().into_owned());
27+
all_symbol_names.push('\n');
28+
}
29+
30+
all_symbol_names
31+
}

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

+3
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;
@@ -18,13 +19,15 @@ use std::path::{Path, PathBuf};
1819
use std::process::{Command, Output};
1920

2021
pub use gimli;
22+
pub use goblin;
2123
pub use object;
2224
pub use regex;
2325
pub use wasmparser;
2426

2527
pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
2628
pub use clang::{clang, Clang};
2729
pub use diff::{diff, Diff};
30+
pub use nm::nm;
2831
pub use llvm_readobj::{llvm_readobj, LlvmReadobj};
2932
pub use run::{run, run_fail};
3033
pub use rustc::{aux_build, rustc, Rustc};

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)