Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b3a96c9

Browse files
committedJul 24, 2024
Auto merge of rust-lang#128147 - lolbinarycat:fmt-write-bloat-rmake, r=<try>
migrate fmt-write-bloat to rmake try-job: aarch64-apple try-job: x86_64-gnu-llvm-18 try-job: dist-x86_64-linux
2 parents 6106b05 + 55d5f85 commit b3a96c9

File tree

6 files changed

+61
-26
lines changed

6 files changed

+61
-26
lines changed
 

‎src/tools/run-make-support/src/env.rs

+7
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ pub fn env_var_os(name: &str) -> OsString {
1717
None => panic!("failed to retrieve environment variable {name:?}"),
1818
}
1919
}
20+
21+
/// Check if `NO_DEBUG_ASSERTIONS` is set (usually this may be set in CI jobs).
22+
#[track_caller]
23+
#[must_use]
24+
pub fn no_debug_assertions() -> bool {
25+
std::env::var_os("NO_DEBUG_ASSERTIONS").is_some()
26+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod run;
2121
pub mod scoped_run;
2222
pub mod string;
2323
pub mod targets;
24+
pub mod symbols;
2425

2526
// Internally we call our fs-related support module as `fs`, but re-export its content as `rfs`
2627
// to tests to avoid colliding with commonly used `use std::fs;`.
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use object::{self, Object, ObjectSymbol, SymbolIterator};
2+
use std::fs;
3+
use std::path::Path;
4+
5+
/// iterate through the symbols in an object file.
6+
///
7+
/// uses a callback because SymbolIterator does not own its data
8+
pub fn with_symbol_iter<P, F, R>(path: P, func: F) -> R
9+
where
10+
P: AsRef<Path>,
11+
//I: Iterator + 'a,
12+
F: FnOnce(&mut SymbolIterator<'_, '_>) -> R,
13+
{
14+
let raw_bytes = fs::read(path).expect("unable to read file");
15+
let f = object::File::parse(raw_bytes.as_slice()).expect("unable to parse file");
16+
let mut iter = f.symbols();
17+
func(&mut iter)
18+
}
19+
20+
pub fn any_symbol_contains(path: impl AsRef<Path>, substrings: &[&str]) -> bool {
21+
with_symbol_iter(path, |syms| {
22+
for sym in syms {
23+
for substring in substrings {
24+
if sym
25+
.name_bytes()
26+
.unwrap()
27+
.windows(substring.len())
28+
.any(|x| x == substring.as_bytes())
29+
{
30+
eprintln!("{:?} contains {}", sym, substring);
31+
return true;
32+
}
33+
}
34+
}
35+
false
36+
})
37+
}

‎src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ run-make/extern-flag-disambiguates/Makefile
2020
run-make/extern-fn-reachable/Makefile
2121
run-make/extern-multiple-copies/Makefile
2222
run-make/extern-multiple-copies2/Makefile
23-
run-make/fmt-write-bloat/Makefile
2423
run-make/foreign-double-unwind/Makefile
2524
run-make/foreign-exceptions/Makefile
2625
run-make/foreign-rust-exceptions/Makefile

‎tests/run-make/fmt-write-bloat/Makefile

-25
This file was deleted.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ ignore-windows
2+
//@ ignore-cross-compile
3+
4+
use run_make_support::{env::no_debug_assertions, rustc, symbols::any_symbol_contains};
5+
6+
fn main() {
7+
rustc().input("main.rs").run();
8+
// panic machinery identifiers, these should not appear in the final binary
9+
let mut panic_syms = vec!["panic_bounds_check", "Debug"];
10+
if no_debug_assertions() {
11+
// if debug assertions are allowed, we need to allow these,
12+
// otherwise, add them to the list of symbols to deny.
13+
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
14+
}
15+
assert!(!any_symbol_contains("main", &panic_syms));
16+
}

0 commit comments

Comments
 (0)
Failed to load comments.