Add linker_static_archive_order lint for -Clink-arg archives placed before referenced dynamic libs - #160201
Add linker_static_archive_order lint for -Clink-arg archives placed before referenced dynamic libs#160201cezarbbb wants to merge 1 commit into
linker_static_archive_order lint for -Clink-arg archives placed before referenced dynamic libs#160201Conversation
|
I think we should only point to |
| // Detect static archives passed via `-Clink-arg` that may be ordered before a dynamic | ||
| // library they reference; `--as-needed` linkers like GNU `ld.bfd` can then drop it. | ||
| // See <https://github.com/rust-lang/rust/issues/154975>. | ||
| warn_static_archive_order(sess, crate_info, flavor); |
There was a problem hiding this comment.
I don't think this lint should be in the middle of the linker code. It can be moved to say the start of run_linker or maybe even to the argument parse code.
That makes sense. I'll do it. |
d73f481 to
e5596e2
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ed before referenced dynamic libs
e5596e2 to
e723d7a
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
See issue #154975
When a static archive is passed via
-Clink-arg, rustc appends it after its own native libraries. With--as-needed, strict left-to-right linkers like GNUld.bfd(unlikelld, which tolerates back-references) can then drop a dynamic library that only that archive references, leaving unresolved symbols.rustc can't tell whether the back-reference actually exists without resolving the archive's symbols, so this is a heuristic lint rather than a fix to the ordering itself. It's Allow by default and carries
ignore_deny_warnings, so it stays silent unless explicitly requested with-Wlinker-static-archive-order, and-D warningswon't promote a possible false positive into an error — only-Dlinker-static-archive-orderwill.The lint fires for GNU
ld-family linkers that don't uselld(bareldorcc-driven), excluding Windows and Darwin where the--as-neededmodel doesn't apply. The diagnostic points at three workarounds:-l static=,-Zpre-link-arg=, and wrapping the dynamic library in--no-as-needed/--as-needed.r? @bjorn3