]> git.lizzy.rs Git - rust.git/commit
Auto merge of #84449 - alexcrichton:metadata-in-object, r=nagisa
authorbors <bors@rust-lang.org>
Fri, 4 Jun 2021 19:29:50 +0000 (19:29 +0000)
committerbors <bors@rust-lang.org>
Fri, 4 Jun 2021 19:29:50 +0000 (19:29 +0000)
commitc79419af0721c614d050f09b95f076da09d37b0d
tree8cedc9ce8a8d9a2ed4a2e4f8ce41816d9c8d22b2
parentefc4e377bf5af45447d63a7e46e2976324df5a27
parent0e0338744df6448de98d54d3aeb576cda893e938
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
Cargo.lock
compiler/rustc_codegen_llvm/src/llvm/ffi.rs