-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
Description
Code
I tried this code (simplified from my library):
#[no_mangle]
pub unsafe extern "C" fn test_no_mangle() {}
I expected to see this happen: Successful compilation during cargo test
Instead, this happened: Linker errors with duplicate symbols for #[no_mangle]
functions
Version it worked on
It most recently worked on: nightly-2025-08-14
Version with regression
rustc +nightly -vV
:
rustc 1.91.0-nightly (8e7795415 2025-08-13)
binary: rustc
commit-hash: 8e7795415acaa9471b5eeb2301915d6996d289ec
commit-date: 2025-08-13
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0
Backtrace
Backtrace
error: linking with `cc` failed: exit status: 1
= note: "cc" "-m64" "/tmp/rustcflOThX/symbols.o" "<257 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/home/user/.cargo/target/debug/deps/libdevela-c196ee63d71a35ed.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libtest-*,libgetopts-*,libunicode_width-*,librustc_std_workspace_std-*,libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*}.rlib" "/home/user/.cargo/target/debug/deps/libdevela_base-2f30b157371083c5.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcflOThX/raw-dylibs" "-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/user/.cargo/target/debug/deps/devela-ed63e5346b66e85e" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
rust-lld: error: duplicate symbol: test_no_mangle
>>> defined at lib.rs:238 (src/lib.rs:238)
>>> /home/user/.cargo/target/debug/deps/devela-5c2b9106189a1e66.5rjh5wt2c596w464wpw7eaq0k.1nc9mqr.rcgu.o:(test_no_mangle)
>>> defined at lib.rs:238 (src/lib.rs:238)
>>> devela-fb6a4d7e6cf82649.59cfjdnj2r4set7kaot6bkd9v.1npt1ar.rcgu.o:(.text.test_no_mangle+0x0) in archive /home/user/.cargo/target/debug/deps/libdevela-fb6a4d7e6cf82649.rlib
rust-lld: error: duplicate symbol: wasm_callback
>>> defined at web_api.rs:152 (src/lang/ffi/js/web/web_api.rs:152)
>>> /home/user/.cargo/target/debug/deps/devela-5c2b9106189a1e66.6khk1lajtpiy3q4448ifwrbe2.0n5b0qy.rcgu.o:(wasm_callback)
>>> defined at web_api.rs:152 (src/lang/ffi/js/web/web_api.rs:152)
>>> devela-fb6a4d7e6cf82649.1u0u674ci58js15eh7fqpgz9u.02kvoz4.rcgu.o:(.text.wasm_callback+0x0) in archive /home/user/.cargo/target/debug/deps/libdevela-fb6a4d7e6cf82649.rlib
collect2: error: ld returned 1 exit status
Additional Information
- Only fails during
cargo test
in debug mode,cargo build
doesn't fail. - Works with LTO enabled in dev profile.
- Requires
alloc/std
enabled. - The error also seems to depend on adding or removing arbitrary safe code in unrelated modules.
- Bisected to commit: 8e77954 (Auto merge of resolve: Split extern prelude into two scopes #144793)
- Workaround: Adding
#[cfg(not(test))]
to#[no_mangle]
functions
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.regression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.