Skip to content

Rust is linking frankenstein binaries when static linking #82912

Closed
@richfelker

Description

@richfelker

This report comes as a result of a user reporting a segfault on call to sqlite3_open in code using the libsqlite3-sys crate with musl libc, where Rust is currently defaulting to static linking. Analysis of the backtrace showed a call to address 0. The issue was speculated and later reproduced on Twitter as Rust's link process emitting DT_NEEDED references to dynamic libraries in a static linked program (where symbolic runtime relocations are never processed and thereby end up evaluating to 0).

I don't understand the mechanism of Rust's linker invocation well enough to know exactly how this is happening, but I assume it's the equivalent of passing -Wl,-Bdynamic in the middle of the link command line to a C compiler driver invoking the linker.

If targeting a static binary, the linker should never be instructed to search dynamic libraries; it should only link static ones, and fail to link if they are not present.

This issue is related to, but orthogonal to, the issue of Rust currently defaulting to static linking with musl libc target. As far as I can tell, it would affect any target with static linking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesO-muslTarget: The musl libcT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions