Function rustc_codegen_ssa::back::link::add_upstream_native_libraries
source · [−]fn add_upstream_native_libraries(
cmd: &mut dyn Linker,
sess: &Session,
codegen_results: &CodegenResults
)
Expand description
Link in all of our upstream crates’ native dependencies. Remember that all of these upstream native dependencies are all non-static dependencies. We’ve got two cases then:
-
The upstream crate is an rlib. In this case we must link in the native dependency because the rlib is just an archive.
-
The upstream crate is a dylib. In order to use the dylib, we have to have the dependency present on the system somewhere. Thus, we don’t gain a whole lot from not linking in the dynamic dependency to this crate as well.
The use case for this is a little subtle. In theory the native dependencies of a crate are purely an implementation detail of the crate itself, but the problem arises with generic and inlined functions. If a generic function calls a native function, then the generic function must be instantiated in the target crate, meaning that the native symbol must also be resolved in the target crate.