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.
This commit is contained in:
parent
9184a5f661
commit
5768fb7d93
3 changed files with 16 additions and 3 deletions
|
|
@ -6,6 +6,7 @@ publish = false
|
|||
|
||||
[dependencies]
|
||||
object = { version = "0.37.3", features = ["wasm"] }
|
||||
regex = "1.12.3"
|
||||
serde_json = "1.0.149"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
|||
|
|
@ -9,12 +9,14 @@ use std::fs;
|
|||
use std::io::{BufRead, BufReader};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use object::read::archive::ArchiveFile;
|
||||
use object::{
|
||||
File as ObjFile, Object, ObjectSection, ObjectSymbol, Result as ObjResult, Symbol, SymbolKind,
|
||||
SymbolScope,
|
||||
};
|
||||
use regex::Regex;
|
||||
use serde_json::Value;
|
||||
|
||||
const CHECK_LIBRARIES: &[&str] = &["compiler_builtins", "builtins_test_intrinsics"];
|
||||
|
|
@ -255,6 +257,14 @@ fn verify_no_duplicates(archive: &BinFile) {
|
|||
|
||||
/// Ensure that there are no references to symbols from `core` that aren't also (somehow) defined.
|
||||
fn verify_core_symbols(archive: &BinFile) {
|
||||
// Match both mangling styles:
|
||||
//
|
||||
// * `_ZN4core3str8converts9from_utf817hd4454ac14cbbb790E` (old)
|
||||
// * `_RNvNtNtCscK9O3IwVk7N_4core3str8converts9from_utf8` (v0)
|
||||
//
|
||||
// Also account for the Apple leading `_`.
|
||||
static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^_?_[RZ].*4core").unwrap());
|
||||
|
||||
let mut defined = BTreeSet::new();
|
||||
let mut undefined = Vec::new();
|
||||
let mut has_symbols = false;
|
||||
|
|
@ -263,7 +273,7 @@ fn verify_core_symbols(archive: &BinFile) {
|
|||
has_symbols = true;
|
||||
|
||||
// Find only symbols from `core`
|
||||
if !symbol.name().unwrap().contains("_ZN4core") {
|
||||
if !RE.is_match(symbol.name().unwrap()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,10 @@ fn test_core_symbols() {
|
|||
let lib_out = dir.path().join("libfoo.rlib");
|
||||
rustc_build(&input_dir().join("core_symbols.rs"), &lib_out, |cmd| cmd);
|
||||
let assert = cargo_bin_cmd!().arg("check").arg(&lib_out).assert();
|
||||
// FIXME(symcheck): this should fail but we don't detect the new mangling.
|
||||
assert.success();
|
||||
assert
|
||||
.failure()
|
||||
.stderr_contains("found 1 undefined symbols from core")
|
||||
.stderr_contains("from_utf8");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue