Skip to content

Symbols from static libraries used by dependent crates are no longer included into cdylib #96192

Closed
@goffrie

Description

@goffrie

Here is the setup. This is all on x86_64-unknown-linux-gnu.

lib.c:

void symbol(void) {}

dep.rs:

extern "C" { fn symbol(); }
pub unsafe fn inner() { symbol(); }

test.rs:

#[no_mangle]
pub unsafe extern "C" fn outer() { dep::inner(); }

Then we run these commands:

# make a static library containing `symbol`
gcc lib.c -o lib.o -c
ar rc liblib.a lib.o
# compile an rlib that uses `symbol`
rustc dep.rs --crate-type rlib
# compile a cdylib that uses the rlib, and attempt to link the static library
rustc test.rs --crate-type cdylib -Lnative=. -lstatic=lib --extern dep=libdep.rlib

Previously, this worked and linked symbol into the resulting cdylib:

# nm libtest.so | grep -w symbol
00000000000066b5 t symbol

However, it now results in an unresolved symbol:

# nm libtest.so | grep -w symbol
                 U symbol

Which seems wrong, since we asked to link liblib.a into libtest.so. The issue also doesn't occur if the static library is used directly from the cdylib crate.

Bisection reveals that the regression occurred in #95501, which is a rollup; the most likely culprit appears to be #93901.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions