-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Allow linking against dylibs in LTO mode #31854
Copy link
Copy link
Open
Labels
-Cprefer-dynamicCodegen option: Prefer dynamic linking to static linking.Codegen option: Prefer dynamic linking to static linking.A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.
Metadata
Metadata
Assignees
Labels
-Cprefer-dynamicCodegen option: Prefer dynamic linking to static linking.Codegen option: Prefer dynamic linking to static linking.A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I would like to build a binary that links against some crates using LTO and others dynamically. (Why? Because I have a dynamic library that contains all of LLVM and is 30MB, slowing down linking. Note that this is not LLVM's own dynamic library, it's a Rust crate compiled to dylib that itself links LLVM statically. One might imagine more generic use cases, e.g. LTOing small dependencies and dynamically linking large ones.) Here's a model:
xa.rs:xb.rs:xc.rs:This can be built successfully without LTO, albeit only if the dylib links libstd dynamically (otherwise you get "cannot satisfy dependencies so
stdonly shows up once"):The binary
xacontains the code fromxa.rsandxb.rslinked statically (but with a conventional linker rather than LTO), and dynamically links againstlibxc.dyliband libstd.But if the last command includes
-C lto, I just get:It would be nice if rustc supported this.
In principle support could also be added for combining LTO and non-LTO static linking, but that would require some method to identify which is desired, since both types refer to
.rlibfiles.