rust/compiler/rustc_codegen_ssa/src/back
bors 63fc57b98e Auto merge of #106560 - bjorn3:support_staticlib_dylib_linking, r=pnkfelix
Support linking to rust dylib with --crate-type staticlib

This allows for example dynamically linking libstd, while statically linking the user crate into an executable or C dynamic library. For this two unstable flags (`-Z staticlib-allow-rdylib-deps` and `-Z staticlib-prefer-dynamic`) are introduced. Without the former you get an error. The latter is the equivalent to `-C prefer-dynamic` for the staticlib crate type to indicate that dynamically linking is preferred when both options are available, like for libstd. Care must be taken to ensure that no crate ends up being merged into two distinct staticlibs that are linked together. Doing so will cause a linker error at best and undefined behavior at worst. In addition two distinct staticlibs compiled by different rustc may not be combined under any circumstances due to some rustc private symbols not being mangled.

To successfully link a staticlib, `--print native-static-libs` can be used while compiling to ask rustc for the linker flags necessary when linking the staticlib. This is an existing flag which previously only listed native libraries. It has been extended to list rust dylibs too. Trying to locate libstd yourself to link against it is not supported and may break if for example the libstd of multiple rustc versions are put in the same directory.

For an example on how to use this see the `src/test/run-make-fulldeps/staticlib-dylib-linkage/` test.
2023-05-10 03:40:40 +00:00
..
rpath Remove LibSource 2021-07-05 10:49:07 +02:00
archive.rs Recognize AIX style archive kind 2023-04-19 11:10:47 +08:00
command.rs Reduce usage of Symbol in the linker code 2022-06-28 18:38:36 +00:00
link.rs Auto merge of #106560 - bjorn3:support_staticlib_dylib_linking, r=pnkfelix 2023-05-10 03:40:40 +00:00
linker.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
lto.rs Merge new_metadata into codegen_allocator 2022-04-30 21:20:08 +02:00
metadata.rs rewriting match on endianness 2023-05-05 19:47:00 +00:00
mod.rs Use the object crate for metadata reading 2021-05-07 18:48:58 +02:00
rpath.rs pass -Wl,-z,origin to set DF_ORIGIN when using rpath 2021-12-17 11:27:14 +00:00
symbol_export.rs Revert "Remove #[alloc_error_handler] from the compiler and library" 2023-04-25 00:08:35 +02:00
write.rs Rollup merge of #110985 - Amanieu:normalize_asm_spans, r=b-naber 2023-05-06 13:30:04 +02:00