rust/compiler/rustc_interface/src
bors c79419af07 Auto merge of #84449 - alexcrichton:metadata-in-object, r=nagisa
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 19:29:50 +00:00
..
callbacks.rs Fix outdated crate names in rustc_interface::callbacks 2021-04-07 11:45:27 -05:00
interface.rs Change the .unwrap to .expect with a helpful message 2021-03-15 20:45:45 +08:00
lib.rs Remove unused feature gates 2021-05-31 13:55:43 +02:00
passes.rs rustc: Store metadata-in-rlibs in object files 2021-06-04 10:05:20 -07:00
proc_macro_decls.rs Use () for proc_macro_decls_static. 2021-05-12 13:58:43 +02:00
queries.rs Don't panic when failing to initialize incremental directory. 2021-05-25 14:40:33 -07:00
tests.rs Don't sort a Vec before computing its DepTrackingHash 2021-05-25 22:11:39 -05:00
util.rs Merge CrateDisambiguator into StableCrateId 2021-05-30 12:51:34 +02:00