Why does `#[no_mangle] fn open() {}` make `cargo t` hang?

I'm on macOS, and if I:

  1. create a new library (cargo new --lib foo);
  2. edit lib.rs to
// lib.rs
fn open() {}

when I run cargo test it hangs forever on Running unittests src/lib.rs. It doesn't if I name the function anything other than open or if I remove the #[no_mangle] attribute.

What's going on?

Given the standard library depends on libc, it may be conflicting with that one, perhaps.

I cannot reproduce the issue on my system with open, but with open64 it does hang for me. Similarly, using a name like memcpy easily results in a crash.

1 Like

Note that no_mangle is technically unsafe #[no_mangle] is unsafe · Issue #28179 · rust-lang/rust · GitHub

Yes, that code was just a MWE.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.