diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index d97ee95652530..b5716b51a91c4 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -228,7 +228,7 @@ fn compute_symbol_name<'tcx>( // However, we don't have the wasm import module map there yet. tcx.is_foreign_item(def_id) && tcx.sess.target.is_like_wasm - && tcx.wasm_import_module_map(LOCAL_CRATE).contains_key(&def_id.into()) + && tcx.wasm_import_module_map(def_id.krate).contains_key(&def_id.into()) }; if !wasm_import_module_exception_force_mangling { diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 4d67ba9248998..0517760c35501 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -5,6 +5,7 @@ use rand::RngCore; target_os = "freebsd", target_os = "linux", target_os = "netbsd", + target_os = "illumos", target_vendor = "apple", ))] use crate::assert_matches::assert_matches; @@ -14,6 +15,7 @@ use crate::char::MAX_LEN_UTF8; target_os = "freebsd", target_os = "linux", target_os = "netbsd", + target_os = "illumos", target_vendor = "apple", ))] use crate::fs::TryLockError; @@ -227,6 +229,7 @@ fn file_test_io_seek_and_write() { target_os = "linux", target_os = "netbsd", target_os = "solaris", + target_os = "illumos", target_vendor = "apple", ))] fn file_lock_multiple_shared() { @@ -251,6 +254,7 @@ fn file_lock_multiple_shared() { target_os = "linux", target_os = "netbsd", target_os = "solaris", + target_os = "illumos", target_vendor = "apple", ))] fn file_lock_blocking() { @@ -276,6 +280,7 @@ fn file_lock_blocking() { target_os = "linux", target_os = "netbsd", target_os = "solaris", + target_os = "illumos", target_vendor = "apple", ))] fn file_lock_drop() { @@ -298,6 +303,7 @@ fn file_lock_drop() { target_os = "linux", target_os = "netbsd", target_os = "solaris", + target_os = "illumos", target_vendor = "apple", ))] fn file_lock_dup() { diff --git a/library/std/src/sys/fs/unix.rs b/library/std/src/sys/fs/unix.rs index d9a7fcb0e2d39..3efe67390d7dd 100644 --- a/library/std/src/sys/fs/unix.rs +++ b/library/std/src/sys/fs/unix.rs @@ -1292,6 +1292,7 @@ impl File { target_os = "netbsd", target_os = "openbsd", target_os = "cygwin", + target_os = "illumos", target_vendor = "apple", ))] pub fn lock(&self) -> io::Result<()> { @@ -1316,6 +1317,7 @@ impl File { target_os = "openbsd", target_os = "cygwin", target_os = "solaris", + target_os = "illumos", target_vendor = "apple", )))] pub fn lock(&self) -> io::Result<()> { @@ -1329,6 +1331,7 @@ impl File { target_os = "netbsd", target_os = "openbsd", target_os = "cygwin", + target_os = "illumos", target_vendor = "apple", ))] pub fn lock_shared(&self) -> io::Result<()> { @@ -1353,6 +1356,7 @@ impl File { target_os = "openbsd", target_os = "cygwin", target_os = "solaris", + target_os = "illumos", target_vendor = "apple", )))] pub fn lock_shared(&self) -> io::Result<()> { @@ -1366,6 +1370,7 @@ impl File { target_os = "netbsd", target_os = "openbsd", target_os = "cygwin", + target_os = "illumos", target_vendor = "apple", ))] pub fn try_lock(&self) -> Result<(), TryLockError> { @@ -1406,6 +1411,7 @@ impl File { target_os = "openbsd", target_os = "cygwin", target_os = "solaris", + target_os = "illumos", target_vendor = "apple", )))] pub fn try_lock(&self) -> Result<(), TryLockError> { @@ -1422,6 +1428,7 @@ impl File { target_os = "netbsd", target_os = "openbsd", target_os = "cygwin", + target_os = "illumos", target_vendor = "apple", ))] pub fn try_lock_shared(&self) -> Result<(), TryLockError> { @@ -1462,6 +1469,7 @@ impl File { target_os = "openbsd", target_os = "cygwin", target_os = "solaris", + target_os = "illumos", target_vendor = "apple", )))] pub fn try_lock_shared(&self) -> Result<(), TryLockError> { @@ -1478,6 +1486,7 @@ impl File { target_os = "netbsd", target_os = "openbsd", target_os = "cygwin", + target_os = "illumos", target_vendor = "apple", ))] pub fn unlock(&self) -> io::Result<()> { @@ -1502,6 +1511,7 @@ impl File { target_os = "openbsd", target_os = "cygwin", target_os = "solaris", + target_os = "illumos", target_vendor = "apple", )))] pub fn unlock(&self) -> io::Result<()> { diff --git a/tests/ui/wasm/auxiliary/link-name-in-foreign-crate.rs b/tests/ui/wasm/auxiliary/link-name-in-foreign-crate.rs new file mode 100644 index 0000000000000..69d508518597e --- /dev/null +++ b/tests/ui/wasm/auxiliary/link-name-in-foreign-crate.rs @@ -0,0 +1,7 @@ +#![no_std] + +#[link(wasm_import_module = "test")] +unsafe extern "C" { + #[link_name = "close"] + pub fn close(x: u32) -> u32; +} diff --git a/tests/ui/wasm/wasm-link-name-in-foreign-crate-respected.rs b/tests/ui/wasm/wasm-link-name-in-foreign-crate-respected.rs new file mode 100644 index 0000000000000..e2ceeb8ae13e2 --- /dev/null +++ b/tests/ui/wasm/wasm-link-name-in-foreign-crate-respected.rs @@ -0,0 +1,22 @@ +//@ only-wasm32 +//@ aux-build:link-name-in-foreign-crate.rs +//@ compile-flags: --crate-type cdylib +//@ build-pass +//@ no-prefer-dynamic + +extern crate link_name_in_foreign_crate; + +// This test that the definition of a function named `close`, which collides +// with the `close` function in libc in theory, is handled correctly in +// cross-crate situations. The `link_name_in_foreign_crate` dependency declares +// `close` from a non-`env` wasm import module and then this crate attempts to +// use the symbol. This should properly ensure that the wasm module name is +// tagged as `test` and the `close` symbol, to LLD, is mangled, to avoid +// colliding with the `close` symbol in libc itself. + +#[unsafe(no_mangle)] +pub extern "C" fn foo() { + unsafe { + link_name_in_foreign_crate::close(1); + } +}