Closed
Description
Minimized example (problem discovered when translating bzip2 to Rust with C2Rust).
main.rs:
mod caller;
#[no_mangle]
#[inline]
pub unsafe extern "C" fn ext_fn() -> i32 { 0 }
pub fn main() { caller::call(); }
caller.rs
extern "C" { #[no_mangle] fn ext_fn() -> i32; }
pub fn call() { unsafe { ext_fn() }; }
NOTE: the problem has to do with the inline attribute; linking succeeds when removed.
$ rustc --version
rustc 1.35.0 (3c235d560 2019-05-20)
$ cargo build
undefined reference to `ext_fn'
whereas the following works (on stable and nightly):
$ RUSTFLAGS="-C link-dead-code" cargo build
Maybe this is not expected to work since ext_fn
isn't defined in a foreign library? On the other hand, it seems like a bug since using the inline attribute shouldn't prevent linking.