Skip to content

Commit 5f5c75d

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 f9fb398 + 44a9b0b commit 5f5c75d

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

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/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(),

test_dependencies/Cargo.lock

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)