Skip to content

Commit 0f34039

Browse files
committed
Auto merge of #2748 - Aaron1011:wasm32-support, r=RalfJung
Ignore symbol shim clash when symbol is provided by compiler_builtins When this happens, we ignore the symbol from `compiler_builtins` in favor of Miri's builtin support. This allows Miri to target platforms like wasm32-unknown-unknown, where functions like `memcmp` are provided by `compiler_builtins`.
2 parents e1968dd + a474872 commit 0f34039

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

src/tools/miri/ci.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ case $HOST_TARGET in
108108
MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests
109109
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple atomic data_race env/var
110110
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
111-
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer
111+
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal no_std integer strings
112+
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std integer strings
112113
MIRI_TEST_TARGET=thumbv7em-none-eabihf MIRI_NO_STD=1 run_tests_minimal no_std # no_std embedded architecture
113114
MIRI_TEST_TARGET=tests/avr.json MIRI_NO_STD=1 run_tests_minimal no_std # JSON target file
114115
;;

src/tools/miri/src/helpers.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
943943
link_name: Symbol,
944944
) -> InterpResult<'tcx, ()> {
945945
self.check_abi(abi, exp_abi)?;
946-
if let Some((body, _)) = self.eval_context_mut().lookup_exported_symbol(link_name)? {
946+
if let Some((body, instance)) = self.eval_context_mut().lookup_exported_symbol(link_name)? {
947+
// If compiler-builtins is providing the symbol, then don't treat it as a clash.
948+
// We'll use our built-in implementation in `emulate_foreign_item_by_name` for increased
949+
// performance. Note that this means we won't catch any undefined behavior in
950+
// compiler-builtins when running other crates, but Miri can still be run on
951+
// compiler-builtins itself (or any crate that uses it as a normal dependency)
952+
if self.eval_context_ref().tcx.is_compiler_builtins(instance.def_id().krate) {
953+
return Ok(());
954+
}
955+
947956
throw_machine_stop!(TerminationInfo::SymbolShimClashing {
948957
link_name,
949958
span: body.span.data(),

src/tools/miri/test_dependencies/Cargo.lock

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ version = "1.3.2"
1414
source = "registry+https://github.com/rust-lang/crates.io-index"
1515
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
1616

17+
[[package]]
18+
name = "bumpalo"
19+
version = "3.11.1"
20+
source = "registry+https://github.com/rust-lang/crates.io-index"
21+
checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
22+
1723
[[package]]
1824
name = "bytes"
1925
version = "1.3.0"
@@ -44,8 +50,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
4450
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
4551
dependencies = [
4652
"cfg-if",
53+
"js-sys",
4754
"libc",
4855
"wasi 0.11.0+wasi-snapshot-preview1",
56+
"wasm-bindgen",
4957
]
5058

5159
[[package]]
@@ -57,6 +65,15 @@ dependencies = [
5765
"libc",
5866
]
5967

68+
[[package]]
69+
name = "js-sys"
70+
version = "0.3.60"
71+
source = "registry+https://github.com/rust-lang/crates.io-index"
72+
checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47"
73+
dependencies = [
74+
"wasm-bindgen",
75+
]
76+
6077
[[package]]
6178
name = "libc"
6279
version = "0.2.139"
@@ -123,6 +140,12 @@ dependencies = [
123140
"libc",
124141
]
125142

143+
[[package]]
144+
name = "once_cell"
145+
version = "1.17.0"
146+
source = "registry+https://github.com/rust-lang/crates.io-index"
147+
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
148+
126149
[[package]]
127150
name = "page_size"
128151
version = "0.5.0"
@@ -316,6 +339,60 @@ version = "0.11.0+wasi-snapshot-preview1"
316339
source = "registry+https://github.com/rust-lang/crates.io-index"
317340
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
318341

342+
[[package]]
343+
name = "wasm-bindgen"
344+
version = "0.2.83"
345+
source = "registry+https://github.com/rust-lang/crates.io-index"
346+
checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
347+
dependencies = [
348+
"cfg-if",
349+
"wasm-bindgen-macro",
350+
]
351+
352+
[[package]]
353+
name = "wasm-bindgen-backend"
354+
version = "0.2.83"
355+
source = "registry+https://github.com/rust-lang/crates.io-index"
356+
checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
357+
dependencies = [
358+
"bumpalo",
359+
"log",
360+
"once_cell",
361+
"proc-macro2",
362+
"quote",
363+
"syn",
364+
"wasm-bindgen-shared",
365+
]
366+
367+
[[package]]
368+
name = "wasm-bindgen-macro"
369+
version = "0.2.83"
370+
source = "registry+https://github.com/rust-lang/crates.io-index"
371+
checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
372+
dependencies = [
373+
"quote",
374+
"wasm-bindgen-macro-support",
375+
]
376+
377+
[[package]]
378+
name = "wasm-bindgen-macro-support"
379+
version = "0.2.83"
380+
source = "registry+https://github.com/rust-lang/crates.io-index"
381+
checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
382+
dependencies = [
383+
"proc-macro2",
384+
"quote",
385+
"syn",
386+
"wasm-bindgen-backend",
387+
"wasm-bindgen-shared",
388+
]
389+
390+
[[package]]
391+
name = "wasm-bindgen-shared"
392+
version = "0.2.83"
393+
source = "registry+https://github.com/rust-lang/crates.io-index"
394+
checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
395+
319396
[[package]]
320397
name = "winapi"
321398
version = "0.3.9"

src/tools/miri/test_dependencies/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ libc = "0.2"
1313
num_cpus = "1.10.1"
1414

1515
getrandom_1 = { package = "getrandom", version = "0.1" }
16-
getrandom = { version = "0.2" }
16+
getrandom = { version = "0.2", features = ["js"] }
1717
rand = { version = "0.8", features = ["small_rng"] }
1818

1919
[target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dependencies]

0 commit comments

Comments
 (0)