-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Rust is linking frankenstein binaries when static linking #82912
Copy link
Copy link
Closed
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesO-muslTarget: The musl libcTarget: The musl libcT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesO-muslTarget: The musl libcTarget: The musl libcT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This report comes as a result of a user reporting a segfault on call to
sqlite3_openin code using thelibsqlite3-syscrate 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_NEEDEDreferences 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,-Bdynamicin 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.