Skip to content

Commit 31afcd4

Browse files
committed
rewrite stable-symbol-names to rmake
1 parent 9bc2269 commit 31afcd4

File tree

5 files changed

+80
-46
lines changed

5 files changed

+80
-46
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
1818
));
1919
}
2020

21+
#[track_caller]
2122
/// An extension of copy which can copy a directory recursively.
2223
pub fn copy_dir_all<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
2324
create_dir_all(&to);
@@ -26,12 +27,19 @@ pub fn copy_dir_all<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
2627
let ty = entry.file_type().unwrap();
2728
if ty.is_dir() {
2829
copy_dir_all(entry.path(), to.as_ref().join(entry.file_name()));
30+
} else if ty.is_symlink() {
31+
copy_symlink(entry.path(), to.as_ref().join(entry.file_name()));
2932
} else {
3033
copy(entry.path(), to.as_ref().join(entry.file_name()));
3134
}
3235
}
3336
}
3437

38+
fn copy_symlink<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
39+
let target_path = fs::read_link(from).unwrap();
40+
std::os::unix::fs::symlink(target_path, to).unwrap();
41+
}
42+
3543
/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message..
3644
#[track_caller]
3745
pub fn create_file<P: AsRef<Path>>(path: P) {

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
// Outputs should be identical.
77
// See https://github.com/rust-lang/rust/issues/34902
88

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

11-
use run_make_support::{fs_wrapper, rust_lib_name, rustc};
11+
//@ ignore-windows
12+
// Reason: When the sysroot gets copied, some symlinks must be re-created,
13+
// which is a privileged action on Windows.
14+
15+
use run_make_support::{bin_name, fs_wrapper, rust_lib_name, rustc};
1216

1317
fn main() {
1418
// test 1: fat lto
1519
rustc().input("reproducible-build-aux.rs").run();
16-
rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
20+
rustc().input("reproducible-build.rs").arg("-Clto=fat").output("reproducible-build").run();
1721
fs_wrapper::rename("reproducible-build", "reproducible-build-a");
18-
rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
22+
rustc().input("reproducible-build.rs").arg("-Clto=fat").output("reproducible-build").run();
1923
assert_eq!(fs_wrapper::read("reproducible-build"), fs_wrapper::read("reproducible-build-a"));
2024

2125
// test 2: sysroot

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)