Skip to content

Commit b25f8a1

Browse files
committed
tests: check wasm compiler_builtins object architecture
Add a run-make test that checks the `.o` members in the prebuilt `libcompiler_builtins` archive for `wasm32-wasip1` are wasm objects. This guards against building wasm compiler-rt fallbacks with the host C toolchain.
1 parent e95e732 commit b25f8a1

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

  • tests/run-make/wasm-compiler-builtins-object-arch
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ only-wasm32-wasip1
2+
3+
use run_make_support::object::read::archive::ArchiveFile;
4+
use run_make_support::{has_extension, has_prefix, rfs, rustc, shallow_find_files};
5+
6+
fn main() {
7+
let libdir = rustc().print("target-libdir").run().stdout_utf8();
8+
let libdir = libdir.trim();
9+
10+
let rlibs = shallow_find_files(libdir, |path| {
11+
has_prefix(path, "libcompiler_builtins") && has_extension(path, "rlib")
12+
});
13+
assert!(!rlibs.is_empty(), "no libcompiler_builtins rlib found in {libdir}");
14+
15+
let data = rfs::read(&rlibs[0]);
16+
let archive = ArchiveFile::parse(&*data).unwrap();
17+
18+
let mut checked = 0usize;
19+
for member in archive.members() {
20+
let member = member.unwrap();
21+
let name = std::str::from_utf8(member.name()).unwrap_or("<invalid-utf8>");
22+
if !name.ends_with(".o") {
23+
continue;
24+
}
25+
let obj_data = member.data(&*data).unwrap();
26+
assert!(
27+
obj_data.starts_with(b"\0asm"),
28+
"object file `{name}` in compiler_builtins rlib is not a wasm binary \
29+
(first bytes: {:02x?}); C compiler-rt fallbacks were built with the wrong \
30+
toolchain — see rust-lang/rust#132802",
31+
&obj_data[..4.min(obj_data.len())]
32+
);
33+
checked += 1;
34+
}
35+
36+
assert!(
37+
checked > 0,
38+
"no .o members found in compiler_builtins rlib — \
39+
C objects were expected on this configuration; \
40+
test may be running without compiler-builtins-c enabled"
41+
);
42+
eprintln!("checked {checked} .o member(s) in compiler_builtins rlib — all wasm");
43+
}

0 commit comments

Comments
 (0)