Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust is linking frankenstein binaries when static linking #82912

Closed
richfelker opened this issue Mar 8, 2021 · 2 comments
Closed

Rust is linking frankenstein binaries when static linking #82912

richfelker opened this issue Mar 8, 2021 · 2 comments
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.

Comments

@richfelker
Copy link

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.

@petrochenkov
Copy link
Contributor

See #71586 (comment) for the catalogue of issues related to static linking.
This one looks similar to #39998 or #71647.

@Amanieu
Copy link
Member

Amanieu commented Oct 3, 2023

This is fixed by #111698.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

4 participants