From 3a92401847b682dc9c8c907b501bd33fb6f257bc Mon Sep 17 00:00:00 2001 From: Raekye Date: Wed, 4 Oct 2023 03:56:34 -0400 Subject: [PATCH] Found cause - rust-lang/rust#47384? --- README.md | 31 +++++++++++++++++++++++++++++++ build.rs | 3 --- src/bin/main.rs | 6 ------ src/bin/with_extern_crate.rs | 5 +++++ src/bin/without_extern_crate.rs | 3 +++ 5 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 README.md delete mode 100644 build.rs delete mode 100644 src/bin/main.rs create mode 100644 src/bin/with_extern_crate.rs create mode 100644 src/bin/without_extern_crate.rs diff --git a/README.md b/README.md new file mode 100644 index 0000000..dfc2b60 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +Functions from the library crate marked `#[no_mangle]` seem to be removed from executables if no references are made to the library, +even when a linker arg like `-rdynamic` is used. +This behaviour seems to be described in this bug report: https://github.com/rust-lang/rust/issues/47384. +However, that bug report is supposedly fixed by https://github.com/rust-lang/rust/pull/95604. + +``` +# cat src/bin/without_extern_crate.rs +fn main() { + println!("Hello, world!"); +} +``` + +``` +# RUSTFLAGS='-C link-arg=-rdynamic' cargo build && nm -g target/debug/without_extern_crate.rs | grep foo +# nothing +``` + +``` +# cat src/bin/with_extern_crate.rs +extern crate export_symbols; + +fn main() { + println!("Hello, world!"); +} +``` + +``` +# RUSTFLAGS='-C link-arg=-rdynamic' cargo build && nm -g target/debug/with_extern_crate.rs | grep foo +000000000006dfa0 T foo1 +000000000006dfb0 T foo2 +``` diff --git a/build.rs b/build.rs deleted file mode 100644 index a97f60a..0000000 --- a/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("cargo:rustc-link-arg-bins=-rdynamic"); -} diff --git a/src/bin/main.rs b/src/bin/main.rs deleted file mode 100644 index e11cac9..0000000 --- a/src/bin/main.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn main() { - // Without referencing foo2, it won't show up in the final executable (neither will foo1). - // By referencing foo2, foo1 also shows up, even though nothing references it? - let _ = export_symbols::foo2; - println!("Hello, world!"); -} diff --git a/src/bin/with_extern_crate.rs b/src/bin/with_extern_crate.rs new file mode 100644 index 0000000..d02f14c --- /dev/null +++ b/src/bin/with_extern_crate.rs @@ -0,0 +1,5 @@ +extern crate export_symbols; + +fn main() { + println!("Hello, world!"); +} diff --git a/src/bin/without_extern_crate.rs b/src/bin/without_extern_crate.rs new file mode 100644 index 0000000..a30eb95 --- /dev/null +++ b/src/bin/without_extern_crate.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}