-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
Metadata
Metadata
Assignees
Labels
A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.