Rust is linking frankenstein binaries when static linking #82912
Labels
A-linkage
Area: linking into static, shared libraries and binaries
O-musl
Target: The musl libc
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
This report comes as a result of a user reporting a segfault on call to
sqlite3_open
in code using thelibsqlite3-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 emittingDT_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.
The text was updated successfully, but these errors were encountered: