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 1389aea

Browse files
committedJul 2, 2024
rewrite stable-symbol-names to rmake
1 parent 9bc2269 commit 1389aea

File tree

4 files changed

+70
-45
lines changed

4 files changed

+70
-45
lines changed
 

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

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ run-make/share-generics-dylib/Makefile
151151
run-make/silly-file-names/Makefile
152152
run-make/simd-ffi/Makefile
153153
run-make/split-debuginfo/Makefile
154-
run-make/stable-symbol-names/Makefile
155154
run-make/static-dylib-by-default/Makefile
156155
run-make/static-extern-type/Makefile
157156
run-make/staticlib-blank-lib/Makefile

‎tests/run-make/reproducible-build-2/rmake.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88

99
//FIXME(Oneirical): excluded ignore-musl ignore-windows ignore-cross-compile
1010

11-
use run_make_support::{fs_wrapper, rust_lib_name, rustc};
11+
use run_make_support::{bin_name, fs_wrapper, rust_lib_name, rustc};
1212

1313
fn main() {
1414
// test 1: fat lto
1515
rustc().input("reproducible-build-aux.rs").run();
1616
rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
17-
fs_wrapper::rename("reproducible-build", "reproducible-build-a");
17+
fs_wrapper::rename(bin_name("reproducible-build"), bin_name("reproducible-build-a"));
1818
rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
19-
assert_eq!(fs_wrapper::read("reproducible-build"), fs_wrapper::read("reproducible-build-a"));
19+
assert_eq!(
20+
fs_wrapper::read(bin_name("reproducible-build")),
21+
fs_wrapper::read(bin_name("reproducible-build-a"))
22+
);
2023

2124
// test 2: sysroot
2225
let sysroot = rustc().print("sysroot").run().stdout_utf8();

‎tests/run-make/stable-symbol-names/Makefile

-41
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// A typo in rustc caused generic symbol names to be non-deterministic -
2+
// that is, it was possible to compile the same file twice with no changes
3+
// and get outputs with different symbol names.
4+
// This test compiles each of the two crates twice, and checks that each output
5+
// contains exactly the same symbol names.
6+
// Additionally, both crates should agree on the same symbol names for monomorphic
7+
// functions.
8+
// See https://github.com/rust-lang/rust/issues/32554
9+
10+
use run_make_support::{fs_wrapper, llvm_readobj, regex, rust_lib_name, rustc};
11+
use std::collections::HashSet;
12+
13+
fn main() {
14+
// test 1: first file
15+
rustc().input("stable-symbol-names1.rs").run();
16+
let sym1 = process_symbols("stable_symbol_names1", "generic_|mono_");
17+
fs_wrapper::remove_file(rust_lib_name("stable_symbol_names1"));
18+
rustc().input("stable-symbol-names1.rs").run();
19+
let sym2 = process_symbols("stable_symbol_names1", "generic_|mono_");
20+
assert_eq!(sym1, sym2);
21+
22+
// test 2: second file
23+
rustc().input("stable-symbol-names2.rs").run();
24+
let sym1 = process_symbols("stable_symbol_names2", "generic_|mono_");
25+
fs_wrapper::remove_file(rust_lib_name("stable_symbol_names2"));
26+
rustc().input("stable-symbol-names2.rs").run();
27+
let sym2 = process_symbols("stable_symbol_names2", "generic_|mono_");
28+
assert_eq!(sym1, sym2);
29+
30+
// test 3: crossed files
31+
let sym1 = process_symbols("stable_symbol_names1", "mono_");
32+
let sym2 = process_symbols("stable_symbol_names2", "mono_");
33+
assert_eq!(sym1, sym2);
34+
}
35+
36+
#[track_caller]
37+
fn process_symbols(path: &str, symbol: &str) -> Vec<String> {
38+
// Dump all symbols.
39+
let out = llvm_readobj().input(rust_lib_name(path)).arg("--symbols").run().stdout_utf8();
40+
// Extract only lines containing `symbol`.
41+
let symbol_regex = regex::Regex::new(symbol).unwrap();
42+
let out = out.lines().filter(|&line| symbol_regex.find(line).is_some());
43+
// From those lines, extract just the symbol name via `regex`, which:
44+
// * always starts with "_ZN" and ends with "E" (`legacy` mangling)
45+
// * always starts with "_R" (`v0` mangling)
46+
let legacy_pattern = regex::Regex::new(r"_ZN.*E").unwrap();
47+
let v0_pattern = regex::Regex::new(r"_R[a-zA-Z0-9_]*").unwrap();
48+
49+
// HashSet - duplicates should be excluded!
50+
let mut symbols: HashSet<String> = HashSet::new();
51+
for line in out {
52+
if let Some(mat) = legacy_pattern.find(line) {
53+
symbols.insert(mat.as_str().to_string());
54+
}
55+
if let Some(mat) = v0_pattern.find(line) {
56+
symbols.insert(mat.as_str().to_string());
57+
}
58+
}
59+
60+
let mut symbols: Vec<String> = symbols.into_iter().collect();
61+
// Sort those symbol names for deterministic comparison.
62+
symbols.sort();
63+
symbols
64+
}

0 commit comments

Comments
 (0)
Failed to load comments.