rust/compiler
Alex Crichton 0e0338744d rustc: Store metadata-in-rlibs in object files
This commit updates how rustc compiler metadata is stored in rlibs.
Previously metadata was stored as a raw file that has the same format as
`--emit metadata`. After this commit, however, the metadata is encoded
into a small object file which has one section which is the contents of
the metadata.

The motivation for this commit is to fix a common case where #83730
arises. The problem is that when rustc crates a `dylib` crate type it
needs to include entire rlib files into the dylib, so it passes
`--whole-archive` (or the equivalent) to the linker. The problem with
this, though, is that the linker will attempt to read all files in the
archive. If the metadata file were left as-is (today) then the linker
would generate an error saying it can't read the file. The previous
solution was to alter the rlib just before linking, creating a new
archive in a temporary directory which has the metadata file removed.

This problem from before this commit is now removed if the metadata file
is stored in an object file that the linker can read. The only caveat we
have to take care of is to ensure that the linker never actually
includes the contents of the object file into the final output. We apply
similar tricks as the `.llvmbc` bytecode sections to do this.

This involved changing the metadata loading code a bit, namely updating
some of the LLVM C APIs used to use non-deprecated ones and fiddling
with the lifetimes a bit to get everything to work out. Otherwise though
this isn't intended to be a functional change really, only that metadata
is stored differently in archives now.

This should end up fixing #83730 because by default dylibs will no
longer have their rlib dependencies "altered" meaning that
split-debuginfo will continue to have valid paths pointing at the
original rlibs. (note that we still "alter" rlibs if LTO is enabled to
remove Rust object files and we also "alter" for the #[link(cfg)]
feature, but that's rarely used).

Closes #83730
2021-06-04 10:05:20 -07:00
..
rustc
rustc_apfloat remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_arena
rustc_ast Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
rustc_ast_lowering Rename take_trait_map. 2021-06-01 20:53:04 +02:00
rustc_ast_passes Stabilize extended_key_value_attributes 2021-05-18 01:01:36 -04:00
rustc_ast_pretty remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_attr remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_builtin_macros remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_codegen_cranelift Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
rustc_codegen_llvm rustc: Store metadata-in-rlibs in object files 2021-06-04 10:05:20 -07:00
rustc_codegen_ssa rustc: Store metadata-in-rlibs in object files 2021-06-04 10:05:20 -07:00
rustc_data_structures Auto merge of #85892 - tmiasko:i, r=oli-obk 2021-06-02 10:47:58 +00:00
rustc_driver Auto merge of #83842 - LeSeulArtichaut:thir-vec, r=nikomatsakis 2021-05-19 18:41:23 +00:00
rustc_error_codes swap function order for better read flow 2021-05-13 13:22:24 +02:00
rustc_errors Miscellaneous inlining improvements 2021-06-02 08:49:58 +02:00
rustc_expand Use correct edition when parsing :pat matchers 2021-05-29 13:09:14 -05:00
rustc_feature Auto merge of #85331 - cjgillot:dirty-dancing, r=Aaron1011 2021-06-01 23:02:52 +00:00
rustc_fs_util
rustc_graphviz
rustc_hir Auto merge of #85892 - tmiasko:i, r=oli-obk 2021-06-02 10:47:58 +00:00
rustc_hir_pretty remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_incremental Auto merge of #85337 - cjgillot:less-anon, r=michaelwoerister 2021-06-02 13:11:41 +00:00
rustc_index Unify feature flags as step_trait 2021-05-26 18:07:10 -04:00
rustc_infer Restrict access to crate_name. 2021-06-02 18:35:32 +02:00
rustc_interface rustc: Store metadata-in-rlibs in object files 2021-06-04 10:05:20 -07:00
rustc_lexer
rustc_lint Rollup merge of #85900 - LingMan:pat_mat, r=petrochenkov 2021-06-03 14:35:38 +09:00
rustc_lint_defs Rollup merge of #85852 - m-ou-se:machineapplicable-docs, r=nikomatsakis 2021-06-03 14:35:30 +09:00
rustc_llvm rustc: Store metadata-in-rlibs in object files 2021-06-04 10:05:20 -07:00
rustc_macros
rustc_metadata Restrict access to crate_name. 2021-06-02 18:35:32 +02:00
rustc_middle Rollup merge of #85934 - tmiasko:is-union, r=jackh726 2021-06-03 14:35:41 +09:00
rustc_mir Auto merge of #85952 - JohnTitor:rollup-r00gu9q, r=JohnTitor 2021-06-03 08:02:39 +00:00
rustc_mir_build Auto merge of #85952 - JohnTitor:rollup-r00gu9q, r=JohnTitor 2021-06-03 08:02:39 +00:00
rustc_parse Don't drop PResult without handling the error 2021-05-30 00:08:42 +02:00
rustc_parse_format remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_passes Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
rustc_plugin_impl Use () for plugin_registrar_fn. 2021-05-12 13:58:43 +02:00
rustc_privacy Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
rustc_query_impl Restrict access to crate_name. 2021-06-02 18:35:32 +02:00
rustc_query_system Make the reasoning more explicit. 2021-06-01 21:46:30 +02:00
rustc_resolve Rollup merge of #85896 - BoxyUwU:remove-fixme-fwd-declared-const-default, r=petrochenkov 2021-06-03 14:35:36 +09:00
rustc_save_analysis Merge CrateDisambiguator into StableCrateId 2021-05-30 12:51:34 +02:00
rustc_serialize
rustc_session Miscellaneous inlining improvements 2021-06-02 08:49:58 +02:00
rustc_span Miscellaneous inlining improvements 2021-06-02 08:49:58 +02:00
rustc_symbol_mangling Restrict access to crate_name. 2021-06-02 18:35:32 +02:00
rustc_target Rollup merge of #85706 - jrmuizel:fpe, r=nagisa 2021-06-03 14:35:28 +09:00
rustc_trait_selection Restrict access to crate_name. 2021-06-02 18:35:32 +02:00
rustc_traits
rustc_ty_utils Restrict access to crate_name. 2021-06-02 18:35:32 +02:00
rustc_type_ir Specialize implementations 2021-05-26 18:07:09 -04:00
rustc_typeck Auto merge of #85952 - JohnTitor:rollup-r00gu9q, r=JohnTitor 2021-06-03 08:02:39 +00:00