Skip to content

Commit 0bb4057

Browse files
committed
symcheck: Check for core symbols with the new mangling
The recent switch in default mangling meant that the check was no longer working correctly. Resolve this by checking for both legacy- and v0-mangled core symbols to the extent that this is possible.
1 parent 49b8f45 commit 0bb4057

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

crates/symbol-check/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ publish = false
66

77
[dependencies]
88
object = { version = "0.37.3", features = ["wasm"] }
9+
regex = "1.12.3"
910
serde_json = "1.0.149"
1011

1112
[dev-dependencies]

crates/symbol-check/src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use std::fs;
99
use std::io::{BufRead, BufReader};
1010
use std::path::{Path, PathBuf};
1111
use std::process::{Command, Stdio};
12+
use std::sync::LazyLock;
1213

1314
use object::read::archive::ArchiveFile;
1415
use object::{
1516
File as ObjFile, Object, ObjectSection, ObjectSymbol, Result as ObjResult, Symbol, SymbolKind,
1617
SymbolScope,
1718
};
19+
use regex::Regex;
1820
use serde_json::Value;
1921

2022
const CHECK_LIBRARIES: &[&str] = &["compiler_builtins", "builtins_test_intrinsics"];
@@ -255,6 +257,14 @@ fn verify_no_duplicates(archive: &BinFile) {
255257

256258
/// Ensure that there are no references to symbols from `core` that aren't also (somehow) defined.
257259
fn verify_core_symbols(archive: &BinFile) {
260+
// Match both mangling styles:
261+
//
262+
// * `_ZN4core3str8converts9from_utf817hd4454ac14cbbb790E` (old)
263+
// * `_RNvNtNtCscK9O3IwVk7N_4core3str8converts9from_utf8` (v0)
264+
//
265+
// Also account for the Apple leading `_`.
266+
static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^_?_[RZ].*4core").unwrap());
267+
258268
let mut defined = BTreeSet::new();
259269
let mut undefined = Vec::new();
260270
let mut has_symbols = false;
@@ -263,7 +273,7 @@ fn verify_core_symbols(archive: &BinFile) {
263273
has_symbols = true;
264274

265275
// Find only symbols from `core`
266-
if !symbol.name().unwrap().contains("_ZN4core") {
276+
if !RE.is_match(symbol.name().unwrap()) {
267277
return;
268278
}
269279

crates/symbol-check/tests/all.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ fn test_core_symbols() {
6666
let lib_out = dir.path().join("libfoo.rlib");
6767
rustc_build(&input_dir().join("core_symbols.rs"), &lib_out, |cmd| cmd);
6868
let assert = cargo_bin_cmd!().arg("check").arg(&lib_out).assert();
69-
// FIXME(symcheck): this should fail but we don't detect the new mangling.
70-
assert.success();
69+
assert
70+
.failure()
71+
.stderr_contains("found 1 undefined symbols from core")
72+
.stderr_contains("from_utf8");
7173
}
7274

7375
#[test]

0 commit comments

Comments
 (0)